GoogleMapsV3
Examples from Google SIte
by Yamini Sontakke
HTML
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true&dummy=.js"></script>
<div id="map-canvas">loading map</div>
CSS
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map-canvas{
width:100%;
height:100%;
}
JavaScript
var map;
function initialize()
{
var mapOptions =
{
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
// Try HTML5 geolocation
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(function(position)
{
var pos = new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);
var infowindow = new google.maps.InfoWindow(
{
map: map,
position: pos,
content: 'Location found using HTML5.'
});
map.setCenter(pos);
}, function()
{
handleNoGeolocation(true);
});
} else {
// Browser doesn't support Geolocation
handleNoGeolocation(false);
}
}
function handleNoGeolocation(errorFlag)
{
if (errorFlag) {
var content = 'Error: The Geolocation service failed.';
} else {
var content = 'Error: Your browser doesn\'t support geolocation.';
}
var options = {
map: map,
position: new google.maps.LatLng(60, 105),
content: content
};
var infowindow = new google.maps.InfoWindow(options);
map.setCenter(options.position);
}
initialize();
//google.maps.event.addDomListener(window, 'load', initialize);