我在mysql中有polyline数据,想用php测量其长度。我查看了距离矩阵api,但它需要origin_addresses 和 destination_addresses,而我没有这些值。
我发现 decodePolylineToArray gist,但当我解码我的polyline时,有很多值。如何测量polyline的长度?我使用php,如果您有其他语言的方法,我可以将其移植到php。
我在mysql中有polyline数据,想用php测量其长度。我查看了距离矩阵api,但它需要origin_addresses 和 destination_addresses,而我没有这些值。
我发现 decodePolylineToArray gist,但当我解码我的polyline时,有很多值。如何测量polyline的长度?我使用php,如果您有其他语言的方法,我可以将其移植到php。
对于折线中的每个路径,您需要使用Haversine公式: http://en.wikipedia.org/wiki/Haversine_formula
对于不同的编程语言,请搜索: https://www.google.ch/search?q=php+haversine+formula&aq=0&oq=php+Haversine&aqs=chrome.1.57j0l3j62l2.8586&sourceid=chrome&ie=UTF-8
这是JS手动计算两点之间距离的好样例Calculate distance between two points in google maps V3,但有一种更简单的方法:
google.maps.geometry.spherical.computeDistanceBetween(path.getAt(i), path.getAt(i+1));
看看这个示例: http://www-users.mat.umk.pl/~kaskader/polyline_simple.html 使用它。
希望对你有所帮助。