我想找到一組緯度經度值並將其分配給一個變量。 我的代碼看起來像這樣獲取不同地點的經度和緯度值到一個值
var k = findLattitudeLongitude("Italy");
console.log(k) // comes undefined
function findLattitudeLongitude(input){
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': input}, function(results, status) {
var location = results[0].geometry.location;
return location;
});
}
但它是未定義的。達到上述要求的最佳方法是什麼?還有其他方法嗎?
可能重複[爲什麼這個變量未定義或沒有返回?](http://stackoverflow.com/questions/12467690/why-is-this-variable-undefined-or-not-returned) – geocodezip