Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6656923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:42:06+00:00 2026-05-26T01:42:06+00:00

I have spent hours on a strange problem with the interpolate function of google

  • 0

I have spent hours on a strange problem with the interpolate function of google maps’ geometry library. (see: http://code.google.com/apis/maps/documentation/javascript/reference.html#spherical)
I use the following javascript code to illustrate the problem:

// 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);
}

It appears that the interpolate function does NOT like the second set of lat/lng pairs. It always returns the origin lat/lng rather than the correctly interpolated location based on the fraction passed (1/50 * i).

I tried reversing origin and destination, but the outcome is the same.

Any ideas as to what I’m doing wrong are much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:42:07+00:00Added an answer on May 26, 2026 at 1:42 am

    I think you expect too much accuracy from the interpolation. The difference in the latitudes is 47.45756 - 47.45753 = 0.00003 deg ~ 3.3 meter. The difference in the longitudes is 8.57235- 8.57234 = 0.00001 deg ~ 0.5 meter (very appoximatively, see Wikipedia). Now you divide the approximative Euclidean distance 3m into 50 intervals, looking for points at a distance of ca. 6 cm. Compare this with the Earth equator whose length is about 4,003,020,000 cm.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope this is a relatively easy problem although I have spent hours websearching
I have a problem with php header redirect. I already spent hours trying to
I have spent hours trying to figure this problem and i just can't, so
I have spent hours trying to get my head around a piece of code
I'm feeling frustrated. I have spent hours looking for a good piece of code
I am new in java, I have spent hours for this problem. I will
I have spent hours on a debugging problem only to have a more experienced
I have spent several hours trying to find a means of writing a cross
I have a really frustrating error that I've spent hours looking at and cannot
First, I have already spent the past few hours trying to find a solution

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.