Skip to content

Instantly share code, notes, and snippets.

@zevarito
Created July 26, 2012 13:41
Show Gist options
  • Select an option

  • Save zevarito/3182088 to your computer and use it in GitHub Desktop.

Select an option

Save zevarito/3182088 to your computer and use it in GitHub Desktop.

Revisions

  1. zevarito created this gist Jul 26, 2012.
    47 changes: 47 additions & 0 deletions geolocation.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    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}
    }
    })