Skip to content

Instantly share code, notes, and snippets.

@seanknox
Created November 12, 2012 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanknox/4062822 to your computer and use it in GitHub Desktop.
Save seanknox/4062822 to your computer and use it in GitHub Desktop.
HTML code for HTML5 geolocation + Google Maps
<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