私は次の機能を持っています:
$(function() {
var address = $("#address").text();
var r;
function encodeAddress() {
geocoder = new google.maps.Geocoder();
geocoder.geocode({'address' : address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
results[0].geometry.location
r = results[0].geometry.location
console.log("inside:" + r);
} else {
alert("Google Maps had some trouble finding" + address + status);
}
});
}
encodeAddress()
console.log("outside:" + r);
});
ストリートビューとGmapで使用するためにジオコーディングされた住所を返そうとしています。Insideは正しい値を返し、Outsideはアンダーファインドを返します。
すべての助けに大いに感謝します、私は他のどこかでこの方法で値を返すことは不可能であると読みましたが、信頼できるStackOverflowコミュニティに確認する必要がありました。
前もって感謝します。