Google Maps V3 Geometry Library - Interpolate 不返回预期的 Lat/Lng

dav*_*ave 5 javascript geometry interpolation google-maps-api-3

我花了几个小时来解决谷歌地图几何库的插值函数的一个奇怪问题。(请参阅:http : //code.google.com/apis/maps/documentation/javascript/reference.html#sphereal)我使用以下 javascript 代码来说明问题:

// be sure to include: https://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false

// this works just as expected

var origin = new google.maps.LatLng(47.45732443, 8.570993570000041);
var destination = new google.maps.LatLng(47.45733, 8.570889999999963);
var distance = google.maps.geometry.spherical.computeDistanceBetween(origin, destination);

console.log("origin:\r\nlat: " + origin.lat() + ", lng: " + origin.lng());
console.log("destination:\r\nlat: " + destination.lat() + ", lng: " + destination.lng());
console.log("distance between origin and destination: " + distance);

console.log("interpolating 50 equal segments between origin and destination");
for (i=1; i <= 50; i++) {
    var step = (1/50);
    var interpolated = google.maps.geometry.spherical.interpolate(origin, destination, step * i);
    var distance = google.maps.geometry.spherical.computeDistanceBetween(origin, interpolated);

    console.log("lat: " + interpolated.lat() + ", lng: " + interpolated.lng() + ", dist: " + distance);
}

// the following does not work as expected
// the "interpolated" location is always equal to the origin

var origin = new google.maps.LatLng(47.45756, 8.572350000000029);
var destination = new google.maps.LatLng(47.45753, 8.57233999999994);
var distance = google.maps.geometry.spherical.computeDistanceBetween(origin, destination);

console.log("origin:\r\nlat: " + origin.lat() + ", lng: " + origin.lng());
console.log("destination:\r\nlat: " + destination.lat() + ", lng: " + destination.lng());
console.log("distance between origin and destination: " + distance);

console.log("interpolating 50 equal segments between origin and destination");
for (i=1; i <= 50; i++) {
    var step = (1/50);
    var interpolated = google.maps.geometry.spherical.interpolate(origin, destination, step * i);
    var distance = google.maps.geometry.spherical.computeDistanceBetween(origin, interpolated);

    console.log("lat: " + interpolated.lat() + ", lng: " + interpolated.lng() + ", dist: " + distance);
}
Run Code Online (Sandbox Code Playgroud)

看来插值函数不喜欢第二组纬度/经度对。它总是根据传递的分数 (1/50 * i) 返回原点 lat/lng 而不是正确插入的位置。

我尝试颠倒起点和终点,但结果是一样的。

任何关于我做错了什么的想法都非常感谢!

Jir*_*riz 2

我认为您对插值的准确性期望过高。纬度之差为47.45756 - 47.45753 = 0.00003 deg ~ 3.3 meter。经度的差异是8.57235- 8.57234 = 0.00001 deg ~ 0.5 meter(非常近似,请参见维基百科)。现在,您将近似欧几里得距离3m分为 50 个区间,寻找距离为 ca 的点。6 cm。将此与长度约为 的地球赤道进行比较4,003,020,000 cm