I am using the Golang client library for Google Maps API (github link)
I have to calculate travelled distance by the service provider(like uber and other tracking system does). I have created a API which will get gps coordinates when service provider is moving,and calculating distance using these coordinates. For This I am using Google Distance Matrix API. Now according to google map guidelines I cannot use origins and destinations more 25 (guideline link) , check Other Usage Limits section.
Requirement::
- how can I use complete array of geocodes which helps me calculate distance and used for live tracking(according to google api guidelines It cannot be more than 25)? For this I have created a function in which I am dividing total length of array with 25 and create new array of lat,lang with the reasult interval values of complete array. Function::
func GetCustomRouteCoordinateArray(routeCoordinates []string, customLen int) (newRouteCoordinates []string) {
actualLength := len(routeCoordinates)
al := float64(actualLength)
cl := float64(customLen)
num := al / cl
newLengthInterval := math.Ceil(num)
newnum := int(newLengthInterval)
var inc int
i := 0
for i < customLen {
inc = i*newnum
if inc > actualLength-1 || inc == actualLength-1 {
newRouteCoordinates = append(newRouteCoordinates, routeCoordinates[actualLength-1])
break;
}
newRouteCoordinates = append(newRouteCoordinates, routeCoordinates[inc])
i++
}
return newRouteCoordinates
}
It will return an array of lat,lng string with maximum length = customLen, which is 25 Is this perfect method to resolve this issue?? Or I can handle this using some other method??
- I want to show map on customer end which can do live provider tracking
Problem:: Now I can easily calculate distance by saved geocodes, but for live tracking I need to get gps coordinates on every 5 to 10 second, and in this situation any origin and destination array length can be greater than 25. For this I have created a function in which I am calculating distance using only 11 array elements, and for live tracking using complete array? Is this an accurate method, Or there is any other solution to complete this?