Google Map geocoder not as accurate as a Google maps

后端 未结 2 2081
小蘑菇
小蘑菇 2021-01-15 20:07

I have a database containing addresses that are accurate to building level. When I put these manually into Google Map\'s search, Google Maps finds them no problem - the mark

相关标签:
2条回答
  • 2021-01-15 20:28

    Basically there is a name and an address. Google database can have other name for the same location. You can read my answer here: http://www.stackoverflow.com/questions/12788664/google-maps-api-geocode-returns-different-co-ordinates-then-google-maps/12790012#12790012. In the google response you need to loop through the placemark object to find the most similar location.

    0 讨论(0)
  • 2021-01-15 20:47

    Google Maps uses a number of different data sources to locate search results on the map.

    The entry you are seeing that is "correct" is a Places database entry. See this page and enter you search string (St Clement’s Church, Edge Lane, Chorlton, M21 9JF).

    The geocoder gets is designed to return coordinates for postal addresses, there is not enough information in your string for it to return accurate results:

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

    It looks like it is just returning the geocode for the postcode:

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

    It does look like the geocoder does have that location in it. If I use "St Clement’s Church, Edge Lane", it seems to get the "rooftop" geocode (although it reports "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)
    

    proof of concept fiddle

    code snippet:

    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>

    0 讨论(0)
提交回复
热议问题