Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to find a geographic point between two other points
    text
    copied!<p>For my application I have to find the position of a point on Google map knowing only that it's located between 2 other points and the time (in ms) when the coordinates have been caught.</p> <p>In my code, assumed A and B as the points given and X as the point to find, I: </p> <ol> <li><p>calculate distance between A and B</p></li> <li><p>basing on time I found out the speed (in micro degrees /ms) to travel from A to B</p></li> <li><p>I found the distance from point A and point X (using time and speed) </p></li> <li><p>using similar triangle's rule, I calculate latitude and longitude of point X from point A</p></li> </ol> <p>This workflow bring out errors on the map, so, often the X marker is not on the line between A and B markers.</p> <p>How can I make it works better? Is it a problem with the sphericity of the globe?</p> <p>Thank you to all.</p> <p>Here is the code:</p> <pre><code> int ax = oldPoint.getLatitude(); int ay = oldPoint.getLongitude(); int bx = currentPoint.getLatitude(); int by = currentPoint.getLongitude(); long at = oldPoint.getDataRilevamento(); //get time first point long bt = currentPoint.getDataRilevamento(); // get time second point long xt = x.getDate(); // time of point to find int c1 = bx-ax; int c2 = by-ay; double hyp = Math.sqrt(Math.pow(c1, 2) + Math.pow(c2, 2)); double vel = hyp / (bt-at); double pos = vel*(xt - at); int posx = (int)((pos*c1)/hyp); int posy = (int)((pos*c2)/hyp); x.setLatitude(ax+posx); //set the latitude of X x.setLongitude(ay+posy); // set the longitude of X </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload