I have two known locations and a distance to travel. The start location is: San Francisco lat 37.7576793, lon -122.5076404 The destination location is: Redwood City lat 37.5083527, lon -122.2856248 The distance is approximately 33.992 km How can I calculate the coordinates after 13km distance, traveled on a straight line?
private fun distanceBetweenLocationsInKm(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double {
val theta = lon1 - lon2
var distance =
Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(
deg2rad(theta)
)
distance = Math.acos(distance)
distance = rad2deg(distance)
distance *= Constants.NUMBER_OF_MINUES_IN_A_DEGREE * Constants.STATUTE_MILES_IN_A_NAUTICAL_MILE
distance *= Constants.ONE_MILE_IN_KM
return distance
}
private fun deg2rad(deg: Double): Double {
return deg * Math.PI / 180.0
}
private fun rad2deg(rad: Double): Double {
return rad * 180.0 / Math.PI
}