简体   繁体   中英

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?). 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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