From ebc6cb92bf66f5f6741170936bc8e565c2f8b410 Mon Sep 17 00:00:00 2001 From: Yogesh Sharma Date: Wed, 19 Jul 2017 16:39:20 -0700 Subject: [PATCH] Goto Current Location on map - Added code to auto center to current location - Change zoom to 8 --- gmap.html | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/gmap.html b/gmap.html index b39a30a22..1d6b02188 100644 --- a/gmap.html +++ b/gmap.html @@ -153,11 +153,29 @@ function initialize() { var mapOptions = { center: new google.maps.LatLng(CenterLat, CenterLon), - zoom: 5, + zoom: 8, mapTypeId: google.maps.MapTypeId.ROADMAP }; Map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); + infoWindow = new google.maps.InfoWindow; + // Try HTML5 geolocation. + if (navigator.geolocation) { + navigator.geolocation.getCurrentPosition(function(position) { + var pos = { + lat: position.coords.latitude, + lng: position.coords.longitude + }; + + Map.setCenter(pos); + }, function() { + handleLocationError(true, infoWindow, Map.getCenter()); + }); + } else { + // Browser doesn't support Geolocation + handleLocationError(false, infoWindow, Map.getCenter()); + } + /* Setup our timer to poll from the server. */ window.setInterval(function() { fetchData();