Skip to content

Instantly share code, notes, and snippets.

@ronniej2014
Created June 4, 2015 18:37
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 ronniej2014/9263d4a7440467cb62b0 to your computer and use it in GitHub Desktop.
Save ronniej2014/9263d4a7440467cb62b0 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Geolocation</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body, #map-canvas
{
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script>
<script>
var map;
function initialize()
{
var mapOptions =
{
zoom: 14
};
map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(function(position){
var pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
/** var infowindow = new google.maps.InfoWindow(
{
map: map,
position: pos,
content: 'Location found using HTML5.'
}
);
*/
map.setCenter(pos);
}, function(){
handleNoGeolocation(true);
});
}else{
handleNoGeolocation(false);
}
}
function handleNoGeolocation(errorFlag)
{
if(errorFlag)
{
var content = 'Error: The Geolocation service failed.';
}else{
var content = 'Error: Your browser doesn\t support geolocation.';
}
var options =
{
map: map,
position: new google.maps.LatLng(60, 105),
content: content
}
var infowindow = new google.maps.InfoWindow(options);
map.setCenter(options.position);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas" style="width:480px;height:860px"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment