我花了几个小时来解决谷歌地图几何库的插值函数的一个奇怪问题。(请参阅: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 …Run Code Online (Sandbox Code Playgroud)