Created
November 12, 2012 23:39
-
-
Save seanknox/4062822 to your computer and use it in GitHub Desktop.
HTML code for HTML5 geolocation + Google Maps
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
<style type="text/css"> | |
#mapContainer { | |
height: 500px; | |
width: 800px; | |
border:10px solid #eaeaea; | |
} | |
</style> | |
<script src="http://maps.google.com/maps/api/js?sensor=false"> | |
</script> | |
<script type="text/javascript"> | |
if (navigator.geolocation) { | |
navigator.geolocation.getCurrentPosition(function(position){ | |
var latitude = position.coords.latitude; | |
var longitude = position.coords.longitude; | |
var coords = new google.maps.LatLng(latitude, longitude); | |
var mapOptions = { | |
zoom: 15, | |
center: coords, | |
mapTypeControl: true, | |
navigationControlOptions: { | |
style: google.maps.NavigationControlStyle.SMALL | |
}, | |
mapTypeId: google.maps.MapTypeId.ROADMAP | |
}; | |
map = new google.maps.Map( | |
document.getElementById("mapContainer"), mapOptions | |
); | |
var marker = new google.maps.Marker({ | |
position: coords, | |
map: map, | |
title: "Your current location!" | |
}); | |
}); | |
}else { | |
alert("Geolocation API is not supported in your browser."); | |
} | |
</script> | |
<div id="mapContainer"></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment