gMaps.js在单击的标记上平移到地图中心
gMaps.js pan to center map over marker that is clicked
我一直在环顾四周,我使用gMaps.js链接是:http://hpneo.github.io/gmaps/
我有一个 for 循环,它遍历我所有的坐标(经度和纬度),并在所有其他城市放置标记。问题是当我单击地图围绕它的标记时,我希望
。我试过:
.click(function() {
map.panTo(23,43);
}
也:
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
我的Gmap区域如下:
$(document).ready(function(){
$("#tell").hide();
map = new GMaps({
div: '#googleMap',
lat: listRecCenters[4].latitude, //property map (city) in list at array index 4 no quotes
lng: listRecCenters[4].longitude,
zoom: 10,
});
for(i = 0; i < listRecCenters.length; i++)
{
map.addMarker({
lat: listRecCenters[i].latitude,
lng: listRecCenters[i].longitude,
title: listRecCenters[i].city,
infoWindow: {content: "<p class = '"info'"><img src = '"img/rec.jpg'" style = '"float:right;margin:-10px; padding-right:4px;padding-top:4px;width:40px; height:40px;'"></span>" + listRecCenters[i].name + "<br><span class = '"addcolor'">" + listRecCenters[i].addr
+ "<br/>" + listRecCenters[i].city + listRecCenters[i].phone + "</span>" + "<span class = '"myUrl'"><a href = '"http://maps.google.com/?q=" + listRecCenters[i].addr + " "+listRecCenters[i].city + ",Ontario, Canada'">Google Link</a><a <a href = '"http://maps.google.com/maps/geo?output=xml&q" + listRecCenters[i].addr + " "+listRecCenters[i].city + ",Ontario, Canada'">Lat/Long</a><a</span></p>"
}
});
});
任何帮助将不胜感激,似乎没有什么可以做到这一点。非常感谢您阅读我的帖子。如果您需要更多答案,我很乐意发布它们。
这对
我有用:
map.addMarker({
lat: -12.04,
lng: -77.02,
title: 'Marker with InfoWindow',
infoWindow: {
content: '<h3>InfoWindow Content</h3>lat: -12.04<br>lng: -77.02<br>'
},
click: function(e) {
map.map.panTo(e.position);
}
});
点击侦听器来自文档中的示例,map
对象是GMaps()
对象,panTo
方法需要一个google.maps.map对象,该对象存储在GMap.map属性中。
var map = new GMaps({
div: '#map',
lat: -12.043333,
lng: -77.028333
});
map.addMarker({
lat: -12.043333,
lng: -77.028333,
title: 'Marker with InfoWindow',
infoWindow: {
content: '<h3>InfoWindow Content</h3>lat: -12.043333<br>lng: -77.028333<br>'
},
click: function(e) {
map.map.panTo(e.position);
}
});
map.addMarker({
lat: -12.04,
lng: -77.02,
title: 'Marker with InfoWindow',
infoWindow: {
content: '<h3>InfoWindow Content</h3>lat: -12.04<br>lng: -77.02<br>'
},
click: function(e) {
map.map.panTo(e.position);
}
});
html,
body,
#map {
display: block;
width: 100%;
height: 100%;
}
#map {
background: #58B;
}
<script src="http://maps.google.com/maps/api/js"></script>
<script src="https://rawgithub.com/HPNeo/gmaps/master/gmaps.js"></script>
<div id="map"></div>
相关文章:
- 谷歌地图JS API+JSON-多个标记没有显示
- 谷歌地图 JS APIV3.
- 谷歌地图JS API-如何使用fitBounds响应地图
- 如何在本地而非CDN中包含谷歌地图JS库
- 用谷歌地图js api v3制作路线动画
- 谷歌地图JS只是显示了一个灰色框
- 谷歌地图 JS API v3 - 简单的多重标记 v2
- HERE 地图 (JS v3) - 将事件侦听器添加到信息气泡
- 谷歌地图 JS API v3:使用 containsLocation() 获取圆圈标记不起作用 - 为什么
- 带有 d3 的嵌入式 Google 地图.js叠加层显示 UI 选项和叠加元素,但不是地图本身
- 使用 QGIS 和 D3 可视化自定义地图.js会受到投影的损害
- 无法加载高图.js和高图.js(地图.js不起作用)
- 谷歌地图js不显示在chrome或opera中
- 在谷歌地图 JS API 上获取两个点之间的点的纬度和经度(按百分比)
- 地图不显示与谷歌地图 js API 一起
- 地理位置地图 JS.
- 错误“包含”未定义在谷歌地图 JS API 中
- 谷歌地图JS v3 MysqlWhile循环
- 谷歌地图JS API V3 addMarker-标记在源代码中回声,没有地图
- Richmarker获取事件.点击谷歌地图js-apiv3