私はこれが初めてですが、ユーザーの W3C ブラウザーのジオコード情報から読み込まれる Google V3 マップがあり、ジオコード オブジェクトから国、州、都市を取得して入力ボックスを更新します。ユーザーが番地を入力したら、Google 経由でジオコーディングし、map.setCenter と setZoom を変更して、更新された地図を表示したいと考えています。それが機能したら、マーカーと情報ウィンドウを追加したいと思います。何時間もの調査と試行にもかかわらず、ジオコードと更新を機能させることができません。Chrome の開発者ツールは、以下の太字で示されている geocoder.geocode 行で実行が停止/失敗したことを示しているようです。関連するコードは次のとおりです。
var map, geocoder, marker, infowindow; //global variables
function initializeMap() {
// Try W3C Geolocation to geolocate desktop user
//initialize Google map, geolocate desktop user, and display after page loads
//find country, state, and city for the user's location - this all works
}
window.onload = initializeMap;
//change the Google Map after a user enters a street address
$("#streetAddress").blur(function() {
//if state, city and street address locations are present
if ( $(this).val().length > 0 && $("#state").val().length > 0 && $("#city3").val().length > 0 ) {
var gAddress = [$(this).val() + ", " + $("#city3").val() + ", " + $("#state").val()] ;
//get coordinates of this address
//if no geocode object exists, create one
if (!geocoder) {
geocoder = new google.maps.Geocoder(); //create Geocoder object else use existing one from initializeMap() ?
}
//create a GeocoderRequest object with user's street address
var geoCoderRequest = {address: gAddress}
//make a Geocoder request
geocoder.geocode( geoCoderRequest, function(results, status) { **//this line fails**
//check if status is OK
if ( status === google.maps.GeocoderStatus.OK) {
//update center of existing map on location returned for this address
map.setCenter(results[0].geometry.location);
map.setZoom(14);
}
});
} else {
return; //no action if gAddress is incomplete
}
});