Getting the user location is a browser feature that most modern browsers support. However, you still need to test for the ability to get the location in your code.
if (navigator.geolocation) { // test for presence of location feature
navigator.geolocation.getCurrentPosition(function(position) {
initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
map.setCenter(initialLocation);
}, function() {
console.log('user denied request for position');
});
} else {
console.log('no geolocation support');
}
0
solved Center map on user’s location (Google Maps API v3)