动态添加标记更改地图-谷歌地图API

Dynamically add markers on changed map - Google Maps API

本文关键字:谷歌地图 API 地图 添加 加标记 动态      更新时间:2023-09-26

我有一张标有零售地点的谷歌地图。

工作正常

如果用户通过拖放改变地图焦点(改变地图提取)我想动态添加新的标记,如果在这个地图提取是一个商店。

我不知道,我在哪里找到这样的例子或别的什么

首先需要加载初始批标记,然后监听"bounds_changed"事件。当该事件触发时,只需获取新的坐标和缩放级别,并相应地加载标记。

你可以在这里找到一个例子:https://developers.google.com/maps/documentation/javascript/events

google.maps.event.addListener(map, 'bounds_changed', function() {
    //Get the new location and zoom parameters
    //and print the new markers
});