有谁知道如何在google maps v3中获取多段线的长度?目前,我正在使用Haversine公式,但如果多段线符合起点,则它会计算最短长度。有谁知道我如何计算折线长度?在google maps v3中获取多段线的长度
非常感谢。 马克
有谁知道如何在google maps v3中获取多段线的长度?目前,我正在使用Haversine公式,但如果多段线符合起点,则它会计算最短长度。有谁知道我如何计算折线长度?在google maps v3中获取多段线的长度
非常感谢。 马克
延长谷歌地图API使用这些功能:
google.maps.LatLng.prototype.kmTo = function(a){
var e = Math, ra = e.PI/180;
var b = this.lat() * ra, c = a.lat() * ra, d = b - c;
var g = this.lng() * ra - a.lng() * ra;
var f = 2 * e.asin(e.sqrt(e.pow(e.sin(d/2), 2) + e.cos(b) * e.cos
(c) * e.pow(e.sin(g/2), 2)));
return f * 6378.137;
}
google.maps.Polyline.prototype.inKm = function(n){
var a = this.getPath(n), len = a.getLength(), dist = 0;
for (var i=0; i < len-1; i++) {
dist += a.getAt(i).kmTo(a.getAt(i+1));
}
return dist;
}
,然后你可以拨打:
var length_in_km = yourPoly.inKm();
来源:http://groups.google.com/forum/#!topic/google-maps-js-api-v3/Op87g7lBotc
使用谷歌几何:
<script type="text/javascript" src="//maps.google.com/maps/api/js?v=3.exp&libraries=geometry"></script>
那么它的那么容易,因为这样的:
var meters = google.maps.geometry.spherical.computeLength(myPolyline.getPath());
真棒。答案应被接受。谢谢 – 2013-01-11 04:36:50