Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage? #8

Open
paulcanning opened this issue Feb 6, 2015 · 2 comments
Open

Usage? #8

paulcanning opened this issue Feb 6, 2015 · 2 comments

Comments

@paulcanning
Copy link

How exactly do I use this?

I tried by adding the .js file into my index.html file, and then in my script, changed getCurrentPosition to getAccurateCurrentPosition (as outlined in the readme)

But all I got was a white splash screen with a spinner.

Could you please explain how to use it properly?

@raratiru
Copy link

I have created a script which defines the geolocationSuccess, geolocationError, geoprogress functions and optionally an options variable. Then I called navigator.geolocation.getAccurateCurrentPosition at the end.

function letsGeolocate {
    var output = document.getElementById("output");  // the div where messages will appear
    var options = {
    };
    function geolocationSuccess(position) {
        var latitude = position.coords.latitude;
        var longitude = position.coords.longitude;
        output.innerHTML = 'Latitude: ' + latitude + '<br/>Longitude: ' + longitude
    }

    function geolocationError() {
        output.innerHTML = "Unable to retrieve your location";
    }

    function geoprogress() {
        output.innerHTML = '<p>Locating in progress</p>';
    }
    navigator.geolocation.getAccurateCurrentPosition(success, error, geoprogress, options);
}

HTML:

<button id='geolocate' onclick=letsGeolocate()>

@kirantpatil
Copy link

@raratiru, thanks, your code helped a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@kirantpatil @paulcanning @raratiru and others