简体   繁体   English

Google maps api:获取Serverside中折线的长度

[英]Google maps api: get length of polyline in Serverside

I have polyline data in mysql. 我在mysql中有折线数据。 I want to measure its length in php. 我想在php中测量它的长度。 I have looked distance matrix api . 我看过距离矩阵api But it requests origin_addresses and destination_addresses , i haven't got those values. 但它请求origin_addresses和destination_addresses,我没有得到这些值。

I found decodePolylineToArray gist but when i decode my polyline, there are a lot of values. 我找到了decodePolylineToArray gist但是当我解码我的折线时,有很多值。 How can i measure length of polyline? 如何测量折线的长度? I am using php but if you have a method in another language, i can port it to php. 我正在使用PHP,但如果你有另一种语言的方法,我可以将其移植到PHP。

You need to use Haversine's formula for every Path in the polyline: http://en.wikipedia.org/wiki/Haversine_formula 您需要为折线中的每个路径使用Haversine公式: http//en.wikipedia.org/wiki/Haversine_formula

For different programming languages search for : https://www.google.ch/search?q=php+haversine+formula&aq=0&oq=php+Haversine&aqs=chrome.1.57j0l3j62l2.8586&sourceid=chrome&ie=UTF-8 对于不同的编程语言,请搜索: https//www.google.ch/search?q = php + haversine + formula&aq = 0 &oq = php +Haversine&aqs = chrome.1.57j0l3j62l2.8586&sourceid = chrome&ie = UTF-8

This is a good sample for manual calculation in JS Calculate distance between two points in google maps V3 , but there is a simpler way: 这是JS 计算谷歌地图V3中两点之间距离的手动计算的一个很好的例子,但有一种更简单的方法:

google.maps.geometry.spherical.computeDistanceBetween(path.getAt(i), path.getAt(i+1));

Check out this sample: http://www-users.mat.umk.pl/~kaskader/polyline_simple.html that uses it. 看看这个样本: http : //www-users.mat.umk.pl/~kaskader/polyline_simple.html使用它。

HTH HTH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM