Created
July 26, 2012 13:41
-
-
Save zevarito/3182088 to your computer and use it in GitHub Desktop.
JS Geolocation sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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