Created
August 28, 2013 01:10
-
-
Save daviosa/6361006 to your computer and use it in GitHub Desktop.
Main JavaScript to load a GoogleMaps on a div (with id "map-canvas"). Try to get user location using HTML5 and put the map centered on the user location. Keywords: Javascript, GoogleMaps API, Maps, GIS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var map; | |
function success(position) { | |
var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); | |
loadMap(latlng); | |
//FROM gMapsMarkers.js | |
//addMarker(latlng); | |
} | |
function error(msg) { | |
//Implement your own! | |
alert(msg); | |
} | |
function loadMap(location){ | |
var mapOptions = { | |
zoom: 14, | |
center: location, | |
mapTypeId: google.maps.MapTypeId.ROADMAP | |
}; | |
map = new google.maps.Map(document.getElementById('map-canvas'), | |
mapOptions); | |
//FROM gMapsMarkers.js | |
//addMarkerOnClick(map); | |
} | |
function gMapsMainInit() { | |
if (navigator.geolocation) { | |
navigator.geolocation.getCurrentPosition(success, error); | |
} else { | |
loadMap(new google.maps.LatLng(-34.397, 150.644)); | |
} | |
} | |
google.maps.event.addDomListener(window, 'load', gMapsMainInit); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment