use*_*923 6 javascript iphone google-maps-api-3 ios ios6-maps
我想显示GoogleMap(Google maps V3 JS)
在UIWebView(ios6)
.
但是,
当我在webview中移动地图时,事件没有火center_changed
.
移动地图已经完成,事件发生火灾.
为什么?
...
有人告诉我页面:
http:
//gmaps-samples-v3.googlecode.com/svn/trunk/map_events/map_events.html Mac'Safri access - center_changed
在地图移动时开火.
iOS6 Safri访问 - 移动地图完成,火灾center_changed
.
......
我想知道移动时地图的中心坐标.
请告诉我一个好方法.
`<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: iPhone Geolocation</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var map;
var moveCenterLat;
var moveCenterLng;
function initialize() {
var myOptions = {
zoom:reqZoomLevel,
disableDefaultUI:true,
draggable:true,
keyboardShortcuts:false,
scrollwheel:false,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
google.maps.event.addListener(map, 'center_changed', function(){
var mce = map.getCenter();
moveCenterLat = mce.lat();
moveCenterLng = mce.lng();
});
}
</script>
</head>
<body style="margin:0px; padding:0px;" onload="initialize()">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>`
Run Code Online (Sandbox Code Playgroud)
laz*_*azd -1
听起来你想要这个drag
活动,而不是center_changed
。来自Google 地图 Javascript API V3 参考:
Drag:当用户拖动地图时,会重复触发此事件。
像这样的东西:
google.maps.event.addListener(map, 'drag', function(){
var mce = map.getCenter();
moveCenterLat = mce.lat();
moveCenterLng = mce.lng();
});
Run Code Online (Sandbox Code Playgroud)
编辑:似乎在拖动时地图边界不再更新,因此尽管在拖动地图时确实会触发拖动事件,但两者getCenter()
都会在拖动开始时返回地图的坐标。感谢@Zubair 指出了这一点。
归档时间: |
|
查看次数: |
2129 次 |
最近记录: |