I'm trying to create a function that will let me give 2 arguments, a new location and a speed to travel at (in meters / second)
It looks like this:
func (l *Location) Move(newLoc *Location, speed float64) {
R := 6371.0 // Kilometers
lat1 := l.Latitude * math.Pi / 180
lat2 := l.Longitude * math.Pi / 180
diffLat := (newLoc.Latitude - l.Latitude) * math.Pi / 180
diffLon := (newLoc.Longitude - l.Longitude) * math.Pi / 180
a := math.Sin(diffLat/2)*math.Sin(diffLat/2) +
math.Cos(lat1)*math.Cos(lat2)*math.Sin(diffLon/2)*math.Sin(diffLon/2)
c := 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))
distanceToMove := R * c // Distance to travel in a straight line, in Kilometers
}
The only thing I'm having trouble with is thinking of the formula to make the latitude, start at its current position, and end up at its new position over a set amount of time.
So say the person changed the latitude from 56.65
to 58.12
and I told it to travel at 1.3m/s
how can I accomplish this. Thanks.