1

まず、私はプログラミングがあまり得意ではなく、ただの初心者なので、そのことを念頭に置いて回答してください。私の問題は、Google マップ v3 を使用したリバース ジオコーディングにあります。インターネットでたくさんの例を見つけて、マップの基本的な動作を確認しましたが、リバース ジオコーディングの部分は、単に動作させることができないという点でイライラしています。「オブジェクト HTMLDivElement」のエラーが発生し続けます。私が問題を抱えているコードの部分は次のとおりです。

  var geocoder = new google.maps.Geocoder();  

  var point = new google.maps.LatLng(38.41054600530499, -112.85153749999995);
    geocoder.geocode({ 'latLng': point }, function (results, status) {
    if (status !== google.maps.GeocoderStatus.OK) {
        alert(status);
    }
    // This is checking to see if the Geoeode Status is OK before proceeding
    if (status == google.maps.GeocoderStatus.OK) {
        console.log(results);
        var address = (results[0].formatted_address);
    }}
    )
  var marker = createMarker(point,"Marker 1", point + "<br> Closest Matching Address:" + address)

マップは引き続き読み込まれますが、インフォボックスには「38.41065600530499、-112.8515374999995; 最も近い一致する住所:["object HTMLDivElement"] と表示されます。

それで、私が変える必要があるのは何ですか?上記のコードに何か問題があることは確かですが、正確には何ですか?

助けてくれてありがとう。

4

1 に答える 1

4

ジオコーダーは非同期です。IE でテストしていて、id="address" の div が必要です。

  var geocoder = new google.maps.Geocoder();  

  var point = new google.maps.LatLng(38.41054600530499, -112.85153749999995);
  geocoder.geocode({ 'latLng': point }, function (results, status) {
    if (status !== google.maps.GeocoderStatus.OK) {
      alert(status);
    }
    // This is checking to see if the Geoeode Status is OK before proceeding
    if (status == google.maps.GeocoderStatus.OK) {
      console.log(results);
      var address = (results[0].formatted_address);
      // create the Marker where the address variable is valid
      var marker = createMarker(point,"Marker 1", point + "<br> Closest Matching Address:" + address)
    }
  });
于 2013-10-16T18:06:16.373 に答える