每当地图移动时如何更新地图视图中心的纬度/经度
在Android应用程序中不断更新mapView的纬度和经度中心的最佳方法是什么?
我需要将其显示在地图顶部显示的标签上。我知道您可以调用 MapViewObject.getMapCenter() 来获取地图中心的 GeoPoint,但是我应该将该代码放在哪里,以便每次用户移动地图或放大时都会调用它/出去?
What is the best way to constantly update the center of a mapView's latitude and longitude in an Android application?
I need to display it on a label that is shown on top of the map. I know you can call MapViewObject.getMapCenter()
to get a GeoPoint of the center of the map, but where would I place that code so that it is called every time the user moves the map or zooms in/out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终通过在叠加层的绘制方法中添加对 getMapCenter 的调用来自己回答了这个问题。
您还可以扩展
MapView
类并将坐标代码放入onInterceptTouchEvent
方法中,这样它仅在用户移动屏幕时更新。这比将其放在覆盖 onDraw 中更有效,因为 onDraw 会不断被调用。I eventually answered the question on my own by adding the call to
getMapCenter
in the draw method of an overlay.You can also extend the
MapView
class and put the coordinate code in theonInterceptTouchEvent
method so it is updated only when the user moves the screen. This would be more efficient than putting it in an overlays onDraw, because onDraw is called constantly.