Skip to content

Instantly share code, notes, and snippets.

@zevarito
Created July 26, 2012 13:41
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 zevarito/3182088 to your computer and use it in GitHub Desktop.
Save zevarito/3182088 to your computer and use it in GitHub Desktop.
JS Geolocation sample
define("Geolocation", {
deviceSupport: function() {
if(navigator.geolocation)
return true;
else if(google.gears)
return true;
else
return false;
},
start: function(success_callback, error_callback) {
// Try W3C Geolocation (Preferred)
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
success_callback(position.coords.latitude, position.coords.longitude);
}, function() {
error_callback();
}, { enableHighAccuracy: true, maximumAge: 600000 });
// Try Google Gears Geolocation
} else if (google.gears) {
var geo = google.gears.factory.create('beta.geolocation');
geo.getCurrentPosition(function(position) {
success_callback(position.latitude, position.longitude);
}, function() {
error_callback;
});
}
},
// Returns a "mocked" like object representing Google LatLng
// Default position is set up to Portland/USA.
default_position: function() {
var latLng = {}
latLng.lat = function() {
return 45.52345150
}
latLng.lng = function() {
return -122.67620710
}
return {latLng: latLng}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment