Wednesday, July 30, 2014

Geolocation woes

Apparently HTML5 has an api to get me exactly where I am on the planet.  But it can't tell me what country I am in.  Google will tell me. Google knows all.

    this.getGeoLocation = function()
    {
        var deferred = $.Deferred();
        if(navigator.geolocation)
        {
            navigator.geolocation.getCurrentPosition(function(position)
            {
                deferred.resolve(position);
                //position: {"coords":{"speed":null,"accuracy":65,"altitudeAccuracy":10,"altitude":1410.8349609375,"longitude":-111.72789187811416,"heading":null,"latitude":40.332329714635044},"timestamp":1406740874211}
            });
        }
        else
        {
            deferred.reject({error: "FAIL"});
        }
     return deferred.promise();
    };

No comments:

Post a Comment