2
votes

I'm using the Circle overlay as part of the V3 of the Google Maps Javascript API (i.e., see below - we have a subsequent call that actually sets radius/etc.) to display goe-spatial locations in our application.

   var circle = new google.maps.Circle({
      fillColor: lCircleColor,
      strokeWeight: 2
    });

We also have a background server process that is calculating distances of points from the center of the circle to determine whether points fall inside or outside the circle - when points fall inside we raise an alarm. There is one particular case we had recently where a point (lat=31.197163, lon=-83.87292) falls right on the border of the circle (lat=31.1998, lon=-83.8738, radius=1000ft).

When using the Haversine formula for calculating distance the calculated distance is greater than the radius whereas Vincenty (more accurate) the distance is less than the radius thus causing an alarm to be generated by the back-end process that the point falls within the location.

My question is related to how Google Maps displays the Circle overlay. When we view it in our application it appears to fall just outside the circle (only visible when zoomed in to the greatest extent). I had read elsewhere that for calculating distance that Google's APIs use the Vincenty algorithm but for displaying their overlay do they assume a spherical shape (and thus maybe explaining why the point appears to fall outside of the circle)?

2
Just to note, this is probably due to an mis-match in your implementation of the various algorithms with googles; e.g. a datum or unit system inconsistency, rounding handling, etc. Further more, Haversine and Vincenty are totally indistinguishable up to about 8 decimal places (~1.11 mm) but the maps api itself is only has a precision to 6 decimal places (~111 mm) so the Vincenty level of precision isn't, as I see it, meaningful for display in Google Maps.Fraser

2 Answers

1
votes

When using the Google map distance calculator on very large distances, for example for two points 9000 km far away from each other, the results are about 2.4‰ (2.4/1000) exceeding the correct answer given by Vincenty's formulae. Somewhat strange that Google could not implement the Vincenty's formulae up to now (July 2020).

0
votes

In Google Maps API V3 these functions are already provided in the ‘spherical’ namespace within the google.maps.geometry library. This library is not loaded by default when you load the Maps Javascript API but must be explicitly specified through use of a libraries bootstrap parameter.

http://code.google.com/apis/maps/documentation/javascript/geometry.html

Once loaded functions such as computeDistanceBetween(), computeHeading(), computeOffset(), interpolate(), are all available.

So you do not have to implement any algorithms yourself and using the internal versions will resolve the discrepancies you are seeing.