2011-05-19 103 views
0

我正在从事谷歌地图项目。我受到3天(真的很长时间)的任务。无法完成任务。我是JavaScript的开端。谷歌地图V3.0位置Api

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> 
+0

怎么办? – ssmsnet 2011-05-19 11:41:06

回答

2

谷歌的地方没有出现在伦敦有非常多的当前时间。当你完全省略类型数组时,它只返回少数几个地方。他们中没有一个似乎是火车站或银行。因此,您必须首先将火车站和银行添加到Google地方信息中。

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

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

0

与此同时,搜索名称=银行或名称=火车+电台(而不是使用类型)可能会给你你想要的。