谷歌地图V3.0放置Api

时间:2011-05-19 11:29:45

标签: javascript google-maps google-maps-api-3

我正在开发一个GoogleMap项目。我对3天的任务感到震惊(真的很长时间)..无法完成任务。我是JavaScript的初学者。

I want to achieve something as shown in the Link for a UK Location. I have changed it to the Uk Location(LONDON) and changed the types to bank. Basically I was expecting the banks pin in the given radius to display. But it is not doing that. I changes the types to train_station, strangley i am getting wrongoutput.

我使用的代码如下所示。 任何人都可以帮助我..

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html> 
<head> 
  <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
  <title>Google Maps JavaScript API v3 Example: Place Search</title> 

  <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&libraries=places"></script> 

  <style type="text/css">
    #map {
      height:500px;
      width:100%;

    }
  </style>

  <script type="text/javascript">

      var map;
      var service;
      var infowindow;

      function initialize() {

      // Australia PostCode
         //var pyrmont = new google.maps.LatLng(-33.8665433, 151.1956316);
          // Uk Post Code
          //Northampton
          //var pyrmont = new google.maps.LatLng(52.238, -0.895);
          //London
          var pyrmont = new google.maps.LatLng(51.4916807, -0.1920284);

        //  var pyrmont = new google.maps.LatLng(40.704, -70.0083);


          map = new google.maps.Map(document.getElementById('map'), {
              mapTypeId: google.maps.MapTypeId.ROADMAP,
              center: pyrmont,
              zoom: 12
          });
          var request = {
              location: pyrmont,
              radius: '50000',
              types: ['train_station']

          };
          infowindow = new google.maps.InfoWindow();
          service = new google.maps.places.PlacesService(map);
          service.search(request, callback);
      }

      function callback(results, status) {
          if (status == google.maps.places.PlacesServiceStatus.OK) {
              for (var i = 0; i < results.length; i++) {
                  var place = results[i];
                  createMarker(results[i]);
              }
          }
      }

      function createMarker(place) {

          var placeLoc = place.geometry.location;
          var marker = new google.maps.Marker({
              map: map,

              position: new google.maps.LatLng(placeLoc.lat(), placeLoc.lng())
          });
          google.maps.event.addListener(marker, 'click', function () {
              infowindow.setContent(place.name);
              infowindow.open(map, this);
          });
      }

  </script> 
</head> 
<body onload="initialize()"> 
  <div id="map"></div>
  <div id="text">
    <pre>
var request = {
  bounds: new google.maps.LatLngBounds(
      new google.maps.LatLng(-33.867114, 151.1957),
      new google.maps.LatLng(-33.866755, 151.196138)),
  types: ['political']
};
    </pre>
    </div>
</body> 
</html> 

2 个答案:

答案 0 :(得分:2)

Google Places目前在伦敦似乎并不多。当你完全省略types数组时,它只返回少数几个地方。它们似乎都不是火车站或银行。因此,您必须先将火车站和银行添加到Google商家信息中。

尽管Google Places for London目前缺乏数据,但该API正在运行。例如,如果您使用“博物馆”作为类型数组中的元素,则可以看到一堆结果。

不知道那个'train_station'错误输出问题是怎么回事。 Google Places API是实验性的。也许你应该向谷歌提交一个错误。问题跟踪器位于http://code.google.com/p/gmaps-api-issues/issues/list。在提交错误时,从第一个下拉项中选择“Places API - Bug”。

答案 1 :(得分:0)

与此同时,搜索name = bank或name = train + station(而不是使用类型)可能会为您提供所需内容。