2

建物レベルまで正確な住所を含むデータベースがあります。これらを Google マップの検索に手動で入力すると、Google マップは問題を検出しません。マーカーは正しい建物のすぐ上に表示されます。ただし、以下のコードを使用してこれらの同じ住所を Google Maps API ジオコーダに渡すと、マーカーは通りにのみ表示され、建物には表示されません。

精度を上げるにはどうすればよいですか?

HTML/PHP:

<div id="addressline"><?php echo theaddress(); ?></div>

JS:

      function myGeocodeFirst() {
        geocoder = new google.maps.Geocoder();

        geocoder.geocode( {'address': document.getElementById("addressline").innerHTML},
          function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
              firstLoc = results[0].geometry.location;
              map = new google.maps.Map(document.getElementById("map_canvas"),
              {
                center: firstLoc,
                zoom: 15,
                mapTypeId: google.maps.MapTypeId.ROADMAP
              });
              markers = new google.maps.Marker({
              position: firstLoc,
              map: map,
        });

            } 
            else {
              document.getElementById("text_status").value = status;
            }
          }
        );
      }
window.onload=myGeocodeFirst;
4

2 に答える 2

3

Google マップでは、さまざまなデータ ソースを使用して地図上の検索結果を特定します。

表示されている「正しい」エントリは、Places データベース エントリです。このページを参照して、検索文字列を入力してください (St Clement's Church, Edge Lane, Chorlton, M21 9JF)。

ジオコーダの get は、住所の座標を返すように設計されています。正確な結果を返すには、文字列に十分な情報がありません。

http://www.geocodezip.com/v3_example_geo2.asp?addr1=St%20Clement%E2%80%99s%20Church,%20Edge%20Lane,%20Chorlton,%20M21%209JF&geocode=1

郵便番号のジオコードを返すだけのようです。

Manchester M21 9JF, UK (53.4414411, -2.285287100000005)

ジオコーダーにはその場所が含まれているようです。"St Clement's Church, Edge Lane" を使用すると、"rooftop" ジオコードを取得しているように見えます (ただし、"APPROXIMATE" と報告されます)。

http://www.geocodezip.com/v3_example_geo2.asp?addr1=St%20Clement%E2%80%99s%20Church,%20Edge%20Lane,%20Chorlton,%20M21%209JF&geocode=1&addr2=St%20Clement%E2%80 %99s%20Church,%20Edge%20Lane&geocode=2

St Clement's Church, 6 Edge Ln, Manchester, Lancashire M21 9JF, UK (53.4406823, -2.283755499999984)

概念実証フィドル

コードスニペット:

var geocoder, map, service, infowindow, bounds;

function initialize() {
  map = new google.maps.Map(
    document.getElementById("map_canvas"), {
      center: new google.maps.LatLng(37.4419, -122.1419),
      zoom: 13,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });
  var request = {
    query: "St Clement’s Church, Edge Lane, Chorlton, M21 9JF"
  }
  infowindow = new google.maps.InfoWindow();
  service = new google.maps.places.PlacesService(map);
  bounds = new google.maps.LatLngBounds();
  service.textSearch(request, callback);

}
google.maps.event.addDomListener(window, "load", initialize);

function callback(results, status) {
  if (status == google.maps.places.PlacesServiceStatus.OK) {
    for (var i = 0; i < results.length; i++) {
      var place = results[i];
      var marker = createMarker(results[i]);
      bounds.extend(marker.getPosition())
    }
    map.fitBounds(bounds);
    google.maps.event.trigger(marker, 'click');
  }
}

function createMarker(place) {
  var placeLoc = place.geometry.location;
  var marker = new google.maps.Marker({
    map: map,
    position: place.geometry.location
  });

  google.maps.event.addListener(marker, 'click', function() {
    infowindow.setContent(place.name);
    infowindow.open(map, this);
  });
  return marker;
}
html,
body,
#map_canvas {
  height: 100%;
  width: 100%;
  margin: 0px;
  padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>
<div id="map_canvas"></div>

于 2012-11-09T18:13:13.253 に答える
1

基本的に住所と氏名です。Google データベースには、同じ場所に別の名前を付けることができます。ここで私の答えを読むことができます: http://www.stackoverflow.com/questions/12788664/google-maps-api-geocode-returns-different-co-ordinates-then-google-maps/12790012#12790012。Google 応答では、目印オブジェクトをループして、最も類似した場所を見つける必要があります。

于 2012-11-09T18:37:29.500 に答える