Skip to content

Instantly share code, notes, and snippets.

@niraj-shah
Created May 21, 2013 14:07
Show Gist options
  • Save niraj-shah/5620051 to your computer and use it in GitHub Desktop.
Save niraj-shah/5620051 to your computer and use it in GitHub Desktop.
function success(position) {
// variable to store the coordinates
var location = position.coords.latitude + ',' + position.coords.longitude;
// setup the map using user location
var mapOptions = {
center: new google.maps.LatLng( position.coords.latitude, position.coords.longitude ),
zoom: 16,
zoomControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// add map to the html
map = new google.maps.Map( document.getElementById("map-canvas"), mapOptions );
// setup the marker
var markers = new google.maps.Marker( {
position:mapOptions.center
});
// add market to the map
markers.setMap(map);
// select the span with id status
var s = $('#status');
// update the status message
s.html('found you!');
}
function error(msg) {
// select the span with id status
var s = $('#status');
// set the error message
s.html(typeof msg == 'string' ? msg : "failed");
}
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
} else {
error('not supported');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment