Generate random geocoordination based on distance

I want to create a method that returns a random CLLocationCoordinate2D (or CLLocation ) object based on another CLLocationCoordinate2D (or CLLocation ). The generated coordinate must be at a certain distance ( not ), so based on the value of CLLocationDistance or the equivalent, not CLLocationDegrees ) of the base coordinate in any random direction. Therefore, I basically generate an arbitrary coordinate within a circular border.

I understand how to do this easily in a conventional coordinate system (just use some basic trigger to calculate a new coordinate from a random angle and radius from the center of the border), however, I am fixated on how to do this in the latitude / longitude system. I could easily do this with a trigger if I wanted to create a random coordinate based on degree differences, but these results will be distorted and I'm closer to the pole, so I want to do this based on distance.

I could not find anything in the documentation that could help me. If there was some way to get a new coordinate, replacing the existing coordinate based on any direction and distance, this would certainly be useful, but I did not find anything for this in the documentation or on the Internet. Any ideas?

+4
source share
1 answer

See this page . A short option: the distances depend on the longitude of the start and end points, and the best / fastest way to calculate this is using a formula known as the Haversive formula. There is also an implementation of Objective-C here .

+2
source

All Articles