【问题标题】: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。我只有 latitude 和 longitude,我需要找到加载到 Google Maps AGM Map (POI) 中的最近位置的place_id。
我已经尝试过(mapClick)="clicked($event)",但这只会传递坐标。 AGM Marker 的点击事件不起作用,因为我不想获取有关我自己的自定义标记的信息。
【问题讨论】:
标签:
google-maps
google-places-api
【解决方案1】:
显然 AGM 团队正在研究一种解决方案,以便在 mapClick 事件中返回 placeId,我需要一个立即解决方案。以下是我为获取 placeId 所做的:
map.component.html:
<agm-map (mapReady)="onMapReady($event)" ... ></agm-map>
map.component.ts:
public onMapReady(map) {
map.addListener('click', (e) => {
...
});
}
在上面的代码中,“e”是包含 placeId 的对象(如果用户点击了某个地点)。如果用户没有点击某个地点,则不会返回 placeId。
然后我使用 placeId 调用 Google Places Details API 以获取有关该地点的数据。
我希望这可以在我们等待 AGM 解决方案时对某人有所帮助。