3

我正在尝试使用 Google Maps 地理编码服务。我复制了代码,它似乎找到了很好的地址(例如“13 Marine Terrace Aberystwyth”),但没有找到像“Rummers Wine Bar,Aberystwyth”这样的其他地方,即使实际的谷歌地图网站根本没有问题。

这是我的代码,稍作修改以用于阿伯里斯特威斯地区,但以其他方式复制形式https://developers.google.com/maps/documentation/javascript/tutorial

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />

        <link rel="stylesheet" type="text/css" href="styles.css" />

    <script type="text/javascript"


/*you can use https if you want it secure!!!    set java scrip sensor to true and read from gps!*/


      src="http://maps.googleapis.com/maps/api/js?key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXo-tdDimvjIs&sensor=false&region=GB">
    </script>
    <script type="text/javascript">

var geocoder;
  var map;
  function initialize() {
     geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(52.4156, -4.0829);
    var myOptions = {
      zoom: 14,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  }

   function codeAddress() {
    var address = document.getElementById("address").value;
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
         map.setCenter(results[0].geometry.location);
         var marker = new google.maps.Marker({
             map: map,
             position: results[0].geometry.location

         });

      } else {
        alert("Geocode was not successful for the following reason: " + status);
      }
            function code ()
                           {document.write(results[0].geometry.location);}
    });
  }
      </script>
    </head>

<body onload="initialize()">
 <div id="map_canvas" style="width: 320px; height: 480px;"></div>
  <div>
   <input id="address" type="textbox" value="aberystwyth">
   <input type="button" value="Encode" onclick="codeAddress()">
  </div>
      </script>
     <script type="text/javascript">
    code();
   </script>
 </body>

这是一个链接:http ://users.aber.ac.uk/avh9/thesite/geocodeaber.html

谁能告诉我为什么以及如何解决它?或地理编码的任何替代方案......

4

1 回答 1

6

Google Maps API 中有一个名为Places Library的库。您可以使用其或方法来搜索 POI 和地标。search() nearbySearch()textSearch()

于 2012-05-02T19:52:39.687 回答