0

I used the code from this link https://developers.google.com/maps/articles/phpsqlajax_v3?hl=nl

I want to display the user current position so the user can see what markers are near them. Instead of displaying the user location the tutorial use coordinates center: new google.maps.LatLng(47.6145, -122.3418)

I tried: center: new google.maps.LatLng(position.coords.latitude, position.coords.longitude); but it didn't work.

Any idea what i'm doing wrong?

Clayton
  • 11
  • 1

1 Answers1

0

Clayton, use navigator.geolocation.getCurrentPosition method providing callback function:

var map = new google.maps.Map(document.getElementById("map"), mapOptions);
if(navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(
        function(position) {
            map.setCenter(new google.maps.LatLng(position.coords.latitude,position.coords.longitude));
        }
       ,function() {
            alert("Geolocation service failed");
        });
}
else
    alert("Your browser doesn't support geolocation");
Maksim Aniskov
  • 371
  • 2
  • 4
  • Maxim thx for reacting. How do i impliment this code in the code i used from this link [link]https://developers.google.com/maps/articles/phpsqlajax_v3 – Clayton Jun 04 '13 at 12:19