Google maps V3 JS no happen “center_changed” from UIWebView iOS6(iPhone)

前提是你 提交于 2019-12-07 03:14:43

问题


I'm trying to display GoogleMap(Google maps V3 JS) in UIWebView(ios6).
but,
When I moveing the map in webview,event no fire center_changed.
Move map has been completed, event fire.
Why?
...
Someone told me page:
http://gmaps-samples-v3.googlecode.com/svn/trunk/map_events/map_events.html
Mac' Safri access - fire center_changed while the map is moving.
iOS6 Safri access - move map is complete, fire center_changed.

...
I want to know the Center-Cordinates of the map while moving.
Please tell me a good way.

`<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>`

回答1:


This is something that doesn't work on google maps on IOS devices. The center_changed is fired when the map is dragged but the center does not update until the drag is complete. So the answer is, 'no', you can not do this.




回答2:


It sounds like you want the drag event, not center_changed. From the Google Maps Javascript API V3 Reference:

drag: this event is repeatedly fired while the user drags the map.

Something like this:

google.maps.event.addListener(map, 'drag', function(){
    var mce = map.getCenter();
    moveCenterLat = mce.lat();
    moveCenterLng = mce.lng();
});

Edit: It seems the map bounds are no longer updated while dragging, so although the drag event does fire while the map is being dragged, both getCenter() returns the coordinates of the map when the drag started. Thanks to @Zubair for pointing this out.



来源:https://stackoverflow.com/questions/12948682/google-maps-v3-js-no-happen-center-changed-from-uiwebview-ios6iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!