kamal
kamal

Reputation: 1193

Google maps api v3, defining user current location

function onPositionUpdate(position) {
    var lat = position.coords.latitude;
    var lng = position.coords.longitude;

    var markerPoint = new google.maps.LatLng(lat, lng);

    var marker = new google.maps.Marker({
        position: markerPoint,
        map: map,
        title: 'Your Location'
    });
}

function button_clicked() {
    if (navigator.geolocation)
        navigator.geolocation.getCurrentPosition(onPositionUpdate);
    else
        alert("navigator.geolocation is not available");
}

This code is running correctly and shows user location. when I try this at home this shows correct address but when I try this at another location this code doesn't show correct address. why? I dont know how this code run exactly(does this code define for IP or other information)

Upvotes: 0

Views: 7673

Answers (2)

Tim
Tim

Reputation: 1

Have you tried :

navigator.geolocation.getCurrentPosition(onPositionUpdate() );

Not sure if your callback has to have brackets or not. It's something I would try.

I also noticed that geolocation takes a little while to narrow down the approximation to a smaller radius. Might have to call position update.

Upvotes: 0

Opi
Opi

Reputation: 1308

You can check if another program can find you. If not, it might be that its not your code which is incorrect:

http://html5demos.com/geo

Some security measures might cause that the client won't share location informations automatically.

Upvotes: 2

Related Questions