地理定位回调永远不会执行错误回调

时间:2012-11-20 23:29:49

标签: javascript jquery asp.net html5 geolocation

代码在此部分停止没有其他事情发生它通过条件然后停止它不会触发任何回调被困在这里&我的应用程序无法提供。

src = "//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js";
src = "//maps.google.com/maps?file=api&v=2.x&key=AIzaSyD4iE2xVSpkLLOXoyqT-RuPwURN3ddScAI";

function getLocation() {
    if (navigator && navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(success);
    }
}

function success(position) {
    //Trials.GetLocationService.setLocation("F"); just testing something i commented it out so it's not the proplem
    printAddress(position.coords.latitude, position.coords.longitude);
}

function printAddress(latitude, longitude) {
    // set up the Geocoder object
    var geocoder = new google.maps.Geocoder();

    // turn coordinates into an object
    var yourLocation = new google.maps.LatLng(latitude, longitude);

    // find out info about our location
    geocoder.geocode({ 'latLng': yourLocation }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            if (results[0]) {
                $('body').append('<p>Your Address:<br />' +
                    results[0].formatted_address + '</p>');
            } else {
                error('Google did not return any results.');
            }
        } else {
            error("Reverse Geocoding failed due to: " + status);
        }
    });
}

0 个答案:

没有答案