I found the answer to my question in another topic, and changed function for my needs. But I did not achieve the desired result. I use this function, and i want get point on radius.
func radiusSearchPoint(coordinate: CLLocationCoordinate2D, radius: CLLocationDistance) -> CLLocationCoordinate2D {
let earthRadius = 6_378_100.0
let π = Double.pi
let lat = coordinate.latitude * π / 180.0
let lng = coordinate.longitude * π / 180.0
let t: Double = 0
let pointLat = lat + (radius / Double(earthRadius)) * sin(t)
let pointLng = lng + (radius / Double(earthRadius)) * cos(t)
let point = CLLocationCoordinate2D(latitude: pointLat * 180 / π, longitude: pointLng * 180 / π)
return point
}
How can I get this point correctly on the radius of a circle?
Welcome to stackoverflow. Check your function values, it looks to me like the red line should end well within the circle (and not on the circle).
The problem you have is that the radius you use to calculate the angle of longitude changes with latitude. As you increase the angle of latitude you define smaller and smaller circles of constant latitude. The radius of a circle of latitude is R * cos(lat). Where R is the earth's radius. Change pointLng
to this:
let pointLng = lng + (radius / Double(earthRadius * cos(lat))) * cos(t)
It's also worth mentioning the earth is not a sphere so you are going to get an error with this calculation which will get worse near the poles. To do this accurately you need to convert to ECEF coordinates to get accurate radius values and back again to WGS84 (lat, lng).