6 <title>Geolocation</title>
7 <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
9 <link href="/maps/documentation/javascript/examples/default.css" rel="stylesheet">
11 Include the maps javascript with sensor=true because this code is using a
12 sensor (a GPS locator) to determine the user's location.
13 See: https://developers.google.com/apis/maps/documentation/javascript/basics#SpecifyingSensor
15 <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true"></script>
20 function initialize() {
23 mapTypeId: google.maps.MapTypeId.ROADMAP
25 map = new google.maps.Map(document.getElementById('map-canvas'),
28 // Try HTML5 geolocation
29 if(navigator.geolocation) {
30 navigator.geolocation.getCurrentPosition(function(position) {
31 var pos = new google.maps.LatLng(position.coords.latitude,
32 position.coords.longitude);
34 var infowindow = new google.maps.InfoWindow({
37 content: 'Location found using HTML5.'
42 handleNoGeolocation(true);
45 // Browser doesn't support Geolocation
46 handleNoGeolocation(false);
50 function handleNoGeolocation(errorFlag) {
52 var content = 'Error: The Geolocation service failed.';
54 var content = 'Error: Your browser doesn\'t support geolocation.';
59 position: new google.maps.LatLng(60, 105),
63 var infowindow = new google.maps.InfoWindow(options);
64 map.setCenter(options.position);
67 google.maps.event.addDomListener(window, 'load', initialize);
72 <div id="map-canvas"></div>