1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/map-geolocation.html Wed Apr 09 12:36:39 2014 +0200
1.3 @@ -0,0 +1,75 @@
1.4 +
1.5 +
1.6 +<!DOCTYPE html>
1.7 +<html>
1.8 + <head>
1.9 + <title>Geolocation</title>
1.10 + <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
1.11 + <meta charset="utf-8">
1.12 + <link href="/maps/documentation/javascript/examples/default.css" rel="stylesheet">
1.13 + <!--
1.14 + Include the maps javascript with sensor=true because this code is using a
1.15 + sensor (a GPS locator) to determine the user's location.
1.16 + See: https://developers.google.com/apis/maps/documentation/javascript/basics#SpecifyingSensor
1.17 + -->
1.18 + <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true"></script>
1.19 +
1.20 + <script>
1.21 +var map;
1.22 +
1.23 +function initialize() {
1.24 + var mapOptions = {
1.25 + zoom: 6,
1.26 + mapTypeId: google.maps.MapTypeId.ROADMAP
1.27 + };
1.28 + map = new google.maps.Map(document.getElementById('map-canvas'),
1.29 + mapOptions);
1.30 +
1.31 + // Try HTML5 geolocation
1.32 + if(navigator.geolocation) {
1.33 + navigator.geolocation.getCurrentPosition(function(position) {
1.34 + var pos = new google.maps.LatLng(position.coords.latitude,
1.35 + position.coords.longitude);
1.36 +
1.37 + var infowindow = new google.maps.InfoWindow({
1.38 + map: map,
1.39 + position: pos,
1.40 + content: 'Location found using HTML5.'
1.41 + });
1.42 +
1.43 + map.setCenter(pos);
1.44 + }, function() {
1.45 + handleNoGeolocation(true);
1.46 + });
1.47 + } else {
1.48 + // Browser doesn't support Geolocation
1.49 + handleNoGeolocation(false);
1.50 + }
1.51 +}
1.52 +
1.53 +function handleNoGeolocation(errorFlag) {
1.54 + if (errorFlag) {
1.55 + var content = 'Error: The Geolocation service failed.';
1.56 + } else {
1.57 + var content = 'Error: Your browser doesn\'t support geolocation.';
1.58 + }
1.59 +
1.60 + var options = {
1.61 + map: map,
1.62 + position: new google.maps.LatLng(60, 105),
1.63 + content: content
1.64 + };
1.65 +
1.66 + var infowindow = new google.maps.InfoWindow(options);
1.67 + map.setCenter(options.position);
1.68 +}
1.69 +
1.70 +google.maps.event.addDomListener(window, 'load', initialize);
1.71 +
1.72 + </script>
1.73 + </head>
1.74 + <body>
1.75 + <div id="map-canvas"></div>
1.76 + </body>
1.77 +</html>
1.78 +