Google地图V3将中心设置为特定标记 [英] Google map V3 Set Center to specific Marker

查看:169
本文介绍了Google地图V3将中心设置为特定标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Google Map V3显示使用MYsql和PHP从数据库中提取的标记列表。
由于我没有Long,Lat信息
,所以我的标记在地图上使用完整地址(来自DB,包括邮编)设置。所有工作正常,MY循环看起来如下

I am using Google Map V3 to display a list of markers pulled from a DB, using MYsql and PHP. MY markers are set on the map using the full address (from DB, including postcode) as I don't have the Long,Lat info All is working fine, MY loop looks as follow

while...
Addmarker(map,'MY ADdress','Title');
end while;

现在我想将地图设置为循环中包含的特定标记,输入邮编。
如何设置地图为中心并打开infowindow?

Now I would like to set the map to a specific marker contained in the loop that will match a previously entered postcode. How can I set the map to center to this marker and open the infowindow?

推荐答案

地图,您可以通过API检索纬度/经度坐标,并使用它来设置地图的中心。您首先需要确定您希望集中哪个标记 - 我会将其留给您。

Once you have markers on the map, you can retrieve the Lat/Long coordinates through the API and use this to set the map's center. You'll first just need to determine which marker you wish to center on - I'll leave that up to you.

// "marker" refers to the Marker object you wish to center on

var latLng = marker.getPosition(); // returns LatLng object
map.setCenter(latLng); // setCenter takes a LatLng object

信息窗口是单独的对象,通常绑定到一个标记,所以打开信息窗口,你可能会做这样的事情(但它取决于你的代码):

Info windows are separate objects which are typically bound to a marker, so to open the info window you might do something like this (however it will depend on your code):

var infoWindow = marker.infoWindow; // retrieve the InfoWindow object
infoWindow.open(map); // Trigger the "open()" method

希望这有助于您。

这篇关于Google地图V3将中心设置为特定标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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