doushan9415 2018-10-31 12:00
浏览 75

如果起点和终点的长度超过25个,我们如何使用Google Distance Matrix API进行实时跟踪?

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::

  1. 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??

  1. 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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题