GoogleMaps getCurrentLocation没有响应

时间:2016-04-05 09:33:03

标签: javascript

我想通过此方法调用获取currentUserPosition:

 getCurrentUserLocation(function(location) {
     console.log(location);
 }.bind(this));


function getCurrentUserLocation(callback) {
    if (navigator.geolocation) {
        browserSupportFlag = true;
        navigator.geolocation.getCurrentPosition(function(position) {
      initialLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
        map.setCenter(initialLocation);
        callback(initialLocation);
    }, function() {
        handleNoGeoLocation(browserSupportFlag);
    });
} else {
    browserSupportFlag = false;
    handleNoGeoLocation(browserSupportFlag);
}

function handleNoGeoLocation(errorFlag) {
    if (errorFlag == true) {
        alert("Geolocation service failed.");
    } else {
        alert("Your browser doesn't support geolocation");
    }
}

但是console.log没有返回值。所以我认为我以错误的方式处理回调?它是记录:

_.M {}lat: ()arguments: (...)caller: (...)length: 0name: ""prototype: Object__proto__: ()<function scope>lng: ()arguments: (...)caller: (...)length: 0name: ""prototype: Object__proto__: ()<function scope>__proto__: Object

https://jsfiddle.net/02ezncwk/

我想通过使用callback(initialLocation)我会将一个处理程序的输出移交给包含的处理程序?

0 个答案:

没有答案