Skip to content

Instantly share code, notes, and snippets.

@alfrekjv
Created January 17, 2013 19:21
Show Gist options
  • Save alfrekjv/4558785 to your computer and use it in GitHub Desktop.
Save alfrekjv/4558785 to your computer and use it in GitHub Desktop.
var map = null,
latitude = null,
longitude = null,
infoWindow = null;
function useDefaultLocation() {
latitude = 31.8391;
longitude = -106.5631;
}
function initialize() {
var myOptions = {
mapTypeId:google.maps.MapTypeId.ROADMAP,
disableDefaultUI: false
};
map = new google.maps.Map(document.getElementById("map"), myOptions);
latlng = new google.maps.LatLng(latitude, longitude);
map.setCenter(latlng);
map.setZoom(9);
}
jQuery(document).ready(function ($) {
initialize();
// check if the geolocation object is supported, if so get position
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
latitude = position.coords.latitude;
longitude = position.coords.longitude;
placeSpotsOnMap();
}, function (e) {
console.log('geolocation failed');
useDefaultLocation();
});
} else {
// browser don't support geo.
useDefaultLocation();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment