To determine the current location of users, it is essential to verify if their browser supports geolocation...
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position){
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
If this condition is met, we can create a map object using the user's geolocation:
var geolocalpoint = new google.maps.LatLng(latitude, longitude);
map.setCenter(geolocalpoint);
var mapOptions = {
zoom: 8,
center: geolocalpoint,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
Next step is to add a marker on the map:
//Place a marker
var geolocation = new google.maps.Marker({
position: geolocalpoint,
map: map,
title: 'Your geolocation',
icon: 'http://labs.google.com/ridefinder/images/mm_20_green.png'
});
});
}
The line mentioning
map.setCenter(geolocalpoint);
is responsible for centering the map on the user's geolocation. Feel free to remove this line if not needed:) Hopefully, this information is useful.