谷歌地图中的移动端触发
Moveend triggering in Google Maps
我正试图在访问者移动地图后通过Json添加标记。由于某些原因,moveend未被捕获和/或函数onClickCallback未被触发。我哪里错了。
google.maps.event.addListener(map, "moveend", function() {
var bounds = this.getBounds();
onClickCallback(map);
});
function onClickCallback(map) {
var bounds = map.getBounds();
// clearOverlays();
$.getJSON( 'http://skiweather.eu/gmap4/markers/index.php', {
swLat: bounds.getSouthWest().lat(), swLon: bounds.getSouthWest().lng(),
neLat: bounds.getNorthEast().lat(), neLon: bounds.getNorthEast().lng()}, function(data) {
$.each( data.markers, function(i, marker) {
// Define Marker properties
var image = new google.maps.MarkerImage(marker.smallimg,
// This marker is 129 pixels wide by 42 pixels tall.
new google.maps.Size(42, 42),
// The origin for this image is 0,0.
new google.maps.Point(0,0),
// The anchor for this image is the base of the flagpole at 18,42.
new google.maps.Point(18, 42)
);
$('#map').gmap('addMarker', { 'id' : marker.id,
'position': new google.maps.LatLng(marker.latitude, marker.longitude),
'icon' : image,
'bounds': true
}).click(function() {
$('#map').gmap('openInfoWindow', { 'content': '<h2>' + marker.loc + '</h2><img src="' + marker.smallimg + '" class="my-map-marker" />'
}, this);
});
});
});
}
google.maps.event.addDomListener(window, 'load', initialize);
moveend
事件在google.maps V3中不再可用。请改用dragend
。
试试这个:
google.maps.event.addListener(map, "dragend", function() {
var bounds = this.getBounds();
onClickCallback(map);
});
我有同样的问题。
我在谷歌参考资料中找到了答案;
事件:空闲
参数:无
当平移或缩放后贴图变为空闲时,会触发此事件。
来自groops谷歌的一篇帖子。
google.mapsV3在整个地图上缺少一些重要的V2事件:
mousemove
mouseover
mouseout
movebegin
moveend
看来bounds_changed
可能会有所帮助。另请参阅用户destopero关于dragend
的评论。
相关文章:
- 谷歌地图API v3不适用于移动浏览器或PhoneGap
- 如何停止地图移动时,鼠标悬停在标记在谷歌地图API 3
- 无法使用谷歌地图获得多页jquery移动版
- 谷歌地图点击事件移动标记
- 如何在谷歌地图上用鼠标移动标记
- 在谷歌地图中用鼠标移动标记
- 谷歌地图中的移动端触发
- 删除/移动谷歌地图标记(jquery ui地图)
- 移动谷歌地图标记上的位置自动完成
- 谷歌地图v3使用在地图上移动的标记
- 通过删除元素来提高谷歌地图API V3在移动设备上的速度
- Jquery 移动错误消息,当没有互联网连接加载谷歌地图
- Jquery移动谷歌地图,我必须刷新页面,以显示地图
- 地理定位:只移动谷歌地图标记,而不重新加载地图
- 移动谷歌地图api代码到单独的文件+ jquery
- 防止地图刷新时,标记移动-谷歌地图API
- 单击按钮时移动谷歌地图标记
- 无法向移动谷歌地图添加标记
- 移动谷歌地图中心点点击
- 如何移动谷歌地图的中心位置