我有js功能,她从邮政编码中计算纬度和经度:
function GetLocation(adr, callback) {
var address = adr;
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
// console.log([latitude, longitude])
callback([latitude, longitude]);
} else {
return "Request failed.";
}
});
}

当我在原点调用函数时:
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (p) {
var myRouter = {
map_: null,
directionsHelper_: null,
calcRoute: function() {
var waypts = [];
for (var i in this.stores) {
waypts.push({
location: this.stores[i].location,
stopover:true
});
}
var request = {
origin: new google.maps.LatLng(
GetLocation(adress1, function(callback) {
console.log(callback[0]);
}),
GetLocation(adress1, function(callback) {
console.log(callback[1]);
})
),

回调返回为空,如果之前调用if(navigator.geolocation)那可以,我该如何解决?