Reputation: 1077
I have a MKPolyline
with two points (a start and an ending point), on a MKMapView
. Is there any way to get some intermediate points (or coordinates) along with the line, or to split the line in many segments?
I want something like this: https://i.sstatic.net/qiu39.png, where the black endpoints are the starting and ending points of the line and red points are the ones who I want to get. Sorry for the bad drawing, but I made it in an online drawing tool.
Thank you
Upvotes: 1
Views: 551
Reputation: 8304
Are the lines you're interpolating quite short, geographically? If so you can just scale linearly along the line. If you want 10 segments then work out the difference between the start and end point's latitude values and same for the longitude. After your existing start point the next point will be (lat + 0.1*latDif, lng + 0.1*lngDif), then (lat + 0.2*latDif, lng + 0.2*lngDif). All pretty simple so long as you're prepared to assume the coordinates exist in a uniform grid, which they don't really but it might be fine if you're using it on a city-scale map.
Upvotes: 1