如何在不擦除标记的情况下动态更改Google地图的中心? [英] How to dynamically change the centre of a google maps without erasing markers?

查看:104
本文介绍了如何在不擦除标记的情况下动态更改Google地图的中心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最初,我的地图将指向用户的当前位置。我正在给出一个选择,他可以从自动完成框中选择一个城市,一旦他从自动完成选择新的位置,我将获得一个新的(lat,lng)坐标,我希望将其聚焦到我的地图上。

根据我对Maps API的了解,我可以将其视为更改中心(不过,仅在加载地图时设置中心)。我想在Google地图上实现此用户选择的位置。有人可以帮我吗。提前致谢。使用Google Maps js api v3。 您可以简单地使用 map.setCenter(LatLng )。此方法不会使用任何其他标记,也不会删除现有的标记。您也可以通过 panTo(LatLng)函数移动地图。这两种方法在地图初始化后也可用。



以下是这些方法的文档


Initially, my map would be pointing to the user's current location. I am giving an option where in he can choose a city from an auto complete box, once he selects the new location from auto complete, I will get a new (lat,lng) coordinates for which I would like to focus my map to.

From my knowledge of Maps API, I am able to think of it as changing the centre(however, the centre is set only while loading the map). I want to achieve this focus to user selected location on google maps. Can some one help me out. Thanks in advance. Using Google Maps js api v3.

解决方案

You can simply move the map with map.setCenter(LatLng). This method will not use any other markers and will not erase existing markers. You could also move the map via the panTo(LatLng) function. Both methods are also available after the map has been initialized.

Here is the documentation for these methods.

这篇关于如何在不擦除标记的情况下动态更改Google地图的中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆