var infowindow = new google.maps.InfoWindow();
var places=[]; //contains the addresses of markers
//Find User GeoLocation to Show On Map for the First TIme Map opens.
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition)
}
else
{
alert("Geolocation is not supported by this browser.");
}
function showPosition(position)
{
latitude=position.coords.latitude;
longitude= position.coords.longitude;
}
//Initialize Google Map Api
function initialize()
{
geocoder = new google.maps.Geocoder();
//Initial Map Variables
var myoptions={
zoom:8,
center:new google.maps.LatLng(latitude,longitude),
mapTypeId:google.maps.MapTypeId.ROADMAP
};
//Initialize Map
map=new google.maps.Map(document.getElementById("map_canvas"),myoptions);
});
}
function getLocation() {
var infowindow = new google.maps.InfoWindow();
var places=[]; //contains the addresses of markers
//Find User GeoLocation to Show On Map for the First TIme Map opens.
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition, function(err) { alert(err + " " + err.code);});
}
else
{
alert("Geolocation is not supported by this browser.");
}
}
function showPosition(position)
{
latitude=position.coords.latitude;
longitude= position.coords.longitude;
initialize(latitude, longitude);
}
//Initialize Google Map Api
function initialize(latitude, longitude)
{
geocoder = new google.maps.Geocoder();
//Initial Map Variables
var myoptions={
zoom:8,
center:new google.maps.LatLng(latitude,longitude),
mapTypeId:google.maps.MapTypeId.ROADMAP
};
//Initialize Map
map=new google.maps.Map(document.getElementById("map_canvas"),myoptions);
}
<body onload="getLocation()">
<div id="map_canvas"></div>
</body>