views:

40

answers:

0

We are trying to implement geolocation on this mobile app, we get the prompt for location but its not actually updating. Tried to firebug and I am not seeing any posts or responses.

Does anyone see anything immediately wrong?

http://bit.ly/cCMlWv

here is our js function

(function($){

$.extend($.support,{
    geolocation:function(){
        return $.geolocation.support();
    }
});

$.geolocation = {        
    find:function(success, error, options){
        if($.geolocation.support()){
            options = $.extend({highAccuracy: false, track: false}, options);
            ($.geolocation.object())[(options.track ? 'watchPosition' : 'getCurrentPosition')](function(location){
                success(location.coords);
            }, function(){
                error();
            }, {enableHighAccuracy: options.highAccuracy});     
        }else{
            error();                
        }
    },
    object:function(){
        return navigator.geolocation;
    },
    support:function(){
        return ($.geolocation.object()) ? true : false;
    }
}

})(jQuery);

then we have this function that runs to get the data

<script type="text/javascript">

    var googleMapApiKey = "***********************";

    $(function () {

        if ($.cookie("current_address") == null) {
            $.geolocation.find(function (location) {
                $.ajax({
                    type: "get",
                    dataType: "jsonp",
                    url: getGeolocationUrl(location.latitude, location.longitude),
                    complete: function () { },
                    success: function (data) {
                        if (data.Status.code == "200" && data.Placemark.length > 0) {
                            var city = data.Placemark[0].AddressDetails.Country.AdministrativeArea.Locality.LocalityName;
                            var state = data.Placemark[0].AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;

                            if (data.Placemark[0].AddressDetails.Country.AdministrativeArea.Locality.PostalCode) {
                                var zipcode = data.Placemark[0].AddressDetails.Country.AdministrativeArea.Locality.PostalCode.PostalCodeNumber;
                                $.cookie("current_zipcode", zipcode, {
                                    expires: 10
                                });
                            }
                            var address = data.Placemark[0].address;

                            $.cookie("current_address", address, {
                                expires: 10
                            });
                            $.cookie("current_city", city, {
                                expires: 10
                            });
                            $.cookie("current_state", state, {
                                expires: 10
                            });

                            $("strong.place").html(address);
                        }
                    },
                    error: function () { }
                });

            }, function () {
                alert("Your device doesn't support geolocation");
            });
        } else {
            $("strong.place").html($.cookie("current_address"));
        }
    });


    function getGeolocationUrl(x, y) {
        var url = "http://maps.google.com/maps/geo?q=" + x + "," + y + "&output=json&oe=utf8&sensor=false&key=" + googleMapApiKey;
        return encodeURI(url);
    }

</script>