【问题标题】:List of bus stops from Google Maps谷歌地图上的巴士站列表
【发布时间】:2011-08-21 15:15:54
【问题描述】:

我正在尝试构建网络应用程序,您可以在其中输入您的地址,它会为您提供您所在地区的巴士站列表。我想为此使用谷歌地图,但我找不到为此使用它们的方法。有没有办法以 JSON 或 XML 格式获取地图上的点列表?我尝试了 Google Maps Places API,但它并没有以这种方式工作。我唯一找到的是这个例子 - http://gmaps-samples-v3.googlecode.com/svn/trunk/localsearch/places.html 但这不是我需要的。

那么,有人知道吗?

【问题讨论】:

    标签: google-maps directions


    【解决方案1】:

    Google Places API 上确实有停靠信息,但您需要非常具体地形成查询以使其正常工作。

    关键是使用rankby=distance和radius=和types=bus_station的附近搜索

    默认的rankby prominence很少显示公交车站。

    示例查询:

    https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=49.89458,-97.14137&sensor=true&key=your_key&rankby=distance&types=bus_station

    【讨论】:

    • 我认为这仅适用于公交车站,不适用于公交车站。虽然不完全确定
    • 编辑:不,只有公交车站。不是公交车站。不过总比没有好
    【解决方案2】:

    我觉得可以帮到你

    <script>
      // This example requires the Places library. Include the libraries=places
      // parameter when you first load the API. For example:
      // <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places">
    
      var map;
      var infowindow;
    
      function initMap() {
        var pyrmont = {lat: 38.06908229560463,  lng: 46.31730562744135};
    
        map = new google.maps.Map(document.getElementById('map'), {
          center: pyrmont,
          zoom: 15
        });
    
        infowindow = new google.maps.InfoWindow();
        var service = new google.maps.places.PlacesService(map);
        service.nearbySearch({
          location: pyrmont,
          radius: 1000,
          types: ['bus_station','transit_station']
    
        }, callback);
      }
    
      function callback(results, status) {
        if (status === google.maps.places.PlacesServiceStatus.OK) {
          for (var i = 0; i < results.length; i++) {
            createMarker(results[i]);
          }
        }
      }
    
      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);
        });
      }
    </script>
    

    【讨论】:

      【解决方案3】:

      这不是 Google 提供的服务。他们肯定会记录您需要的所有东西,但他们会在内部进行所有计算。

      一种选择(可能有点困难)是为他们的巴士站位置挖掘公共交通时刻表。如果您的 Web 应用程序要支持一个小区域(即城市),这可能是一个选择。这是有风险的,因为如果页面发生更改,那么您将不得不重新配置数据挖掘应用程序,但尝试从 Google(或其他地方)挖掘数据仍然会遇到同样的问题 - 如果您可以 找到一种方法来获取包含位置的公交车站列表并围绕它构建您的应用程序,它可能随时更改并破坏您的应用程序。

      【讨论】:

      • 我不需要时间表,只需要带有 lat&lng 的巴士站。我有另一个用于时间表的应用程序,但我不想手动挖掘所有公交车站 :) 但是你围绕挖掘软件构建应用程序是对的
      【解决方案4】:

      Ali Seify 的回答是正确的,只是 API 文档指出 API 将仅使用 types 参数中的第一个元素,并且 transit_station 类型是巴士站的正确类型。

      另外,为了获得最近的公交车站,建议使用参数rankBy: google.maps.places.RankBy.DISTANCE,这种情况下不能使用radius参数。

      service.nearbySearch({
        location: pyrmont,
        rankBy: google.maps.places.RankBy.DISTANCE,
        types: ['transit_station']
      
      }, callback);
      

      【讨论】:

        【解决方案5】:

        您可以为此使用Google Fusion Tables。但是,您必须自己输入数据,除非其他人已经输入了数据。 Google 地图 API 支持 Google Fusion Tables。

        【讨论】:

        • 嗯,这与我需要的相反。这是数据 -> 地图上的点,但我需要 gmap 上的点 -> 数据 :) 但是感谢提示,不知道这个项目。
        • 听起来您需要数据(“有没有办法以 JSON 或 XML 格式获取地图上的点列表?”)。如果您已经拥有数据并需要将其导出为 json 或 xml,那会很简单吗?或者也许我只是太累了,无法阅读:)
        • 好吧,也许我写错了。我需要从 gmap 获取数据。我只有地址,我需要获取该地址附近的巴士站列表
        • 您无法仅通过从 Google Maps API 输入地址来获取公交车站列表。默认情况下,该数据不存在。最好的办法是查看 Google Fusion Tables、打开数据 (google.com/search?q=open+data) 或抓取信息。
        • 如上所述,support.google.com/fusiontables/answer/…“Google Fusion Tables”可能不再可用。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-08-18
        • 2018-03-07
        • 1970-01-01
        • 2020-09-06
        • 2020-06-28
        • 1970-01-01
        • 2022-10-13
        相关资源
        最近更新 更多