2016-05-20 10 views
-1

私はstackoverflowの答えを見てきましたが、それを動作させるように見えることはできません。このコードスニペットは、何にもVAR「POS」を設定していません:VarがGoogleのlatlng APIを使用して設定されていません。

var geocoder= new google.maps.Geocoder(); 
var pos = geocoder.geocode({'address': getCookie('banner-location')}, function(results, status) { 
    if (status == google.maps.GeocoderStatus.OK) { 
     return {lat: results[0].geometry.location.lat(), lng: results[0].geometry.location.lng()}; 
    } else { 
     return {lat: 0, lng: 0}; 
    } 
}); 

答えて

0

私はGoogle MapsのAPIに完全に慣れていないんだけど、このGeocoding Serviceページから一目から、あなたが設定する必要があるだろうと思わ応答コールバック機能geocode内のpos変数。応答コールバック関数の戻り値はgeocode's戻り値ではありません。以下は、あなたを助けることがあります。

var geocoder= new google.maps.Geocoder(); 
// Create pos beforehand to use in the callback to retrieve the data 
var pos = null; 
geocoder.geocode({'address': getCookie('banner-location')}, function(results, status) { 
    // Check the status and set the pos variable here 
    if (status == google.maps.GeocoderStatus.OK) { 
     pos = {lat: results[0].geometry.location.lat(), lng: results[0].geometry.location.lng()}; 
    } else { 
     pos = {lat: 0, lng: 0}; 
    } 
}); 

私はgeocode応答コールバックの中にあなたのpos変数を設定しています上。

関連する問題