我想找到一组纬度经度值并将其分配给一个变量。 我的代码看起来像这样获取不同地点的经度和纬度值到一个值
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