【问题标题】:Using AGM Map & Google Places API - how can I pass in a latitude and longitude and retrieve the place_id for the nearest native Google Map location?使用 AGM Map 和 Google Places API - 我如何传递纬度和经度并检索最近的本地 Google Map 位置的 place_id?
【发布时间】:2019-10-09 12:21:36
【问题描述】:

我需要使用 Google Places API 获取位置数据,但我没有 place_id。我只有 latitudelongitude,我需要找到加载到 Google Maps AGM Map (POI) 中的最近位置的place_id

我已经尝试过(mapClick)="clicked($event)",但这只会传递坐标。 AGM Marker 的点击事件不起作用,因为我不想获取有关我自己的自定义标记的信息。

【问题讨论】:

    标签: google-maps google-places-api


    【解决方案1】:

    显然 AGM 团队正在研究一种解决方案,以便在 mapClick 事件中返回 placeId,我需要一个立即解决方案。以下是我为获取 placeId 所做的:

    ma​​p.component.html:

    <agm-map (mapReady)="onMapReady($event)" ... ></agm-map>
    

    ma​​p.component.ts:

    public onMapReady(map) {
      map.addListener('click', (e) => {
        ...
      });
    }
    

    在上面的代码中,“e”是包含 placeId 的对象(如果用户点击了某个地点)。如果用户没有点击某个地点,则不会返回 placeId。

    然后我使用 placeId 调用 Google Places Details API 以获取有关该地点的数据。

    我希望这可以在我们等待 AGM 解决方案时对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-25
      • 2014-01-21
      • 1970-01-01
      相关资源
      最近更新 更多