正如Esteban A. Maringolo所说:
是否有人实现了计算距离的基本方法/类 两点之间(纬度,长度)和类似的操作?
答案 0 :(得分:1)
Esteban A. Maringolo发现的解决方案:
distanceFromLat: lat1 long: long1 toLat: lat2 long: long2
"Answer the distance in meters between two coordinates in float number representation."
| lat1Rad lon1Rad lat2Rad lon2Rad earthRadius dLat dLon dLatSinSqrd dLonSinSqrd cosLatLat a c distance |
lat1Rad := lat1 degreesToRadians.
lon1Rad := long1 degreesToRadians.
lat2Rad := lat2 degreesToRadians.
lon2Rad := long2 degreesToRadians.
earthRadius := 6371.00.
dLat := lat2Rad - lat1Rad.
dLon := lon2Rad - lon1Rad.
dLatSinSqrd := (dLat / 2) sin squared.
dLonSinSqrd := (dLon / 2) sin squared.
cosLatLat := lat2Rad cos * lat1Rad cos.
a := dLatSinSqrd + (cosLatLat * dLonSinSqrd).
c := 2 * a sqrt arcSin.
distance := earthRadius * c.
^ distance
答案 1 :(得分:1)
Sven Van Caekenberghe的简单解决方案:
这是在Pharo,Java [Script],Common Lisp中使用多年的公式:
distanceBetween: firstPosition and: secondPosition
"T3GeoTools distanceBetween: 5.33732@50.926 and: 5.49705@50.82733"
| c |
c := (firstPosition y degreeSin * secondPosition y degreeSin)
+ (firstPosition y degreeCos * secondPosition y degreeCos
* (secondPosition x degreesToRadians - firstPosition x degreesToRadians) cos).
c := c >= 0 ifTrue: [ 1 min: c ] ifFalse: [ -1 max: c ].
^ c arcCos * 6371000
这是在WGS84坐标之间。使用此页面作为参考:http://www.movable-type.co.uk/scripts/latlong.html