1

I am developing a web application using Google Maps to draw circles in the map. This circles are stored in a MySQL 5.7 database, and its representation is done with Polygon object from JTS library.

A circle is stored with center and radius too. When a circle polygon is drawn in Google Maps, center and radius are obtained from database and then the circle object of Google Maps is created.

The results of drawing a circle vary when it is drawn with the polygon object from Google Maps and its center and radius stored in database, and when it is drawn from the Polygon stored in database. There are some differences, in meters, between both bounds.

As is shown in this example:

circle bound differences

The black border circle is drawn with Google Maps Circle object and the fuchsia border circle is drawn with Google Maps Polygon object. Zoom is set up to the maximum value. As you can appreciate is quite similar, but there is an error, about 2 o 3 meters. In this example, the circle has a radius of 8.000 m (8 km) and is located in Madrid.

This problem grows when radius circle is bigger.

Probably, this error occurs because of the use of JTS library I don't know if using a geodesic library, like Spatial4j, solve this (I've tried this but I've have another problems and, as I mentioned before, I don't know if this is the solution).

Thank you very much!

  • is an error of 2m in 8000m significant to your problem? – Ian Turton Feb 17 '17 at 09:10
  • Yes, is very significant in this context, because the fuchsia area represents a not allowed area, and precision is needed. – Miguel Ángel García Feb 17 '17 at 09:30
  • in that case using google maps is probably inappropriate as it uses a spherical representation of the Earth and then a Mercator projection to make a flat map, as you have seen both these choices cause difficulties with accuracy. – Ian Turton Feb 17 '17 at 09:35
  • So, what would the best map representation insted of using Google Maps and MySQL? I mean, the best representation with accuracy. Thank you! – Miguel Ángel García Feb 20 '17 at 06:39
  • probably openlayers or leaflet as client which allow you to pick a local projection, I'd use GeoServer on top of MySQL to support reprojection – Ian Turton Feb 20 '17 at 08:48
  • Thank you @iant! I'll do a deeper study of it ;) – Miguel Ángel García Feb 20 '17 at 10:47
  • But in the context that is shown in te original question, what could the best library to represent the circle in database? E.g. What is the library that I should use to transform the circle, given by its center and radius, to a polygon in the same reference system as Google Maps do? – Miguel Ángel García Feb 20 '17 at 11:39
  • with google maps +/- 5m is probably the best you can hope for. – Ian Turton Feb 20 '17 at 11:42

1 Answers1

0

I have encountered a similar problem myself. The JTS library is not familiar with curved surfaces and only works with 2D plains. This is a geometry library and not a geography library. After searching in a few libraries (geolatte-geom and GeographicLib), I found the GeoTools library which I believe should work for you too. Here is a reference that I hope would help you: How to use GeometricShapeFactory in geoTools to create a Circle on map. And one last important thing: Make sure you use the right coordinate system (the most common one is wgs84).