私は次のコードでアドレスで緯度と経度を取得しようとしている:GoogleマップAPI - ジオコード()は戻りません緯度と長い
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
geocoder = new google.maps.Geocoder();
var address = "HaYarkon 100 TelAviv Israel";
geocoder.geocode({ 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK)
{
TelAviv = new google.maps.LatLng(results[0].geometry.location.latitude,results[0].geometry.location.longitude);
}
});
var myOptions = {
zoom:7,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: TelAviv
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
directionsDisplay.setMap(map);
}
問題があるという結果[0]。 geomety.location.latitudeと経度は未定です。
私は、コンソールに結果に表示することは次のとおりです。
location: O
$a: 51.5414691
ab: -0.11492010000006303
なぜそれが$ aを示し、abが代わりに緯度と経度
優秀、thx! – Alon
あなたの例では、新しい 'google.maps.LatLng'を作成する必要はありません。 'results [0] .geometry.location'はgoogle.maps.LatLng'です。 –
@Sean Mickey、多分あなたは別の問題を助けることができます、私はそのデータをスクリプト内の変数に保存できないようです。どうすればそれを保存して使用できますか? – Alon