Skip to content

Instantly share code, notes, and snippets.

@andrewn
Created February 15, 2011 16:13
Show Gist options
  • Save andrewn/827717 to your computer and use it in GitHub Desktop.
Save andrewn/827717 to your computer and use it in GitHub Desktop.
locator.geo.getCurrentPosition(
function ( pos ) {
var lat = pos.coords.latitude,
lon = pos.coords.longitude;
// now use locator to search for a matching location
// in the gazetter
locator.searchByCoordinatesWithRadius(
lon,
lat,
10000,
function (res) {
if ( res.results.length > 0 ) {
locator.setSharedLocationId(
res.results[0].loc + '~' + res.results[0].site_name
);
}
}
);
} // end callback
); // end get position
(function() {
/**
W3C GeoLocation module
@experimental
@module
Currently uses:
- W3C Geolocation API (Firefox 3.5+, MobileSafari)
- Google Gears Geolocation (if Gears is installed,
and gears_init.js script is included).
See: http://code.google.com/apis/gears/design.html#detecting
*/
var GeoLocationNS = {
// W3C Geolocation Google Gears
isSupported: !!(navigator.geolocation) || !!(window.google && google.gears),
getCurrentPosition: function ( successCallback, errorCallback, opts ) {
// W3C Geolocation API
if ( navigator.geolocation ) {
navigator.geolocation.getCurrentPosition(
successCallback,
errorCallback,
opts
);
// Google Gears Geolocation API
} else if ( google.gears ) {
var geo = google.gears.factory.create('beta.geolocation');
geo.getCurrentPosition( successCallback, errorCallback, opts);
} else {
errorCallback({
code: 2,
message: 'User agent doesn\'t support geolocation interface'
});
}
},
/**
These are also part of the W3C spec but are currently
inimplemented.
*/
watchPosition: function () {
throw new Error('watchPosition is not implemented');
},
clearWatch: function () {
throw new Error('clearWatch is not implemented');
}
};
// Namespace and attach to global locator
if (!window.locator) { window.locator = {}; }
window.locator.geo = GeoLocationNS;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment