如何在 MKMapView 上画一条线来显示用户走过的路线?
我在网上浏览了一下,试图找到绘制一条显示用户行驶路线的线的最佳方法。我想我需要使用 MKOverlayView,并且我想我需要收集一些数据点来绘制(这些是 GPS 坐标吗?)。我的问题是基于如何绘制界限并随着用户位置更新而不断添加?
我还希望能够在用户按下按钮时清除线路。我将如何实现这个(不是按下按钮,只是清除地图视图上的线的代码)?
提前致谢!
I have had a look around online to try and find out the best way to draw a line showing the route a user has travelled. I think I need to use the MKOverlayView, and I guess I need to collect a selection of data points to plot (would these be GPS coordinates?). The question I have is based on how I would draw the line and keep adding to it as the users location updates?
I also want to be able to clear the line when a user presses a button. How would I implement this (not the button press, just the code to clear the line off the map view)?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 MKPolyline 来完成此操作。首先,您需要获取路线的坐标,然后在其上绘制折线。您可以在此处找到示例在某些坐标上绘制折线。
You can do this using MKPolyline. At First you need to get coordinates of route, then draw polylines over it. You will find an example here to draw polyline over some coordinates.