简体   繁体   English

如何在MKMapView上绘制一条线来显示用户所采用的路线?

[英]How to draw a line on MKMapView showing the route a user has taken?

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?). 我想我需要使用MKOverlayView,我想我需要收集一些数据点来绘制(这些是GPS坐标吗?)。 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! 提前致谢!

You can do this using MKPolyline. 你可以使用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. 您将在此处找到一些示例以在某些坐标上绘制折线。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM