Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to use `PolyUtil.encode()` to save important Polygons on Google Maps?

I'm working with a maps application, One of the functionality of this app is to allow the user to draw a polygon on the map for specific task.

This Polygon will be save on our servers for later use.

I managed to encode the points and produce an encoded string path to reduce the size of storing and transferring the polygon from and to the server.

String path = PolyUtil.encode(latLngs); // Android

But I read on Google developer webiste that:

Polyline encoding is a lossy compression algorithm that allows you to store a series of coordinates as a single string. Point coordinates are encoded using signed values. If you only have a few static points, you may also wish to use the interactive polyline encoding utility.

I get a shock when read this :( because I use encodedPath in more than one App. What does they mean by lossy compression ?

So is it safe to use this type for storing users' polygons ?

I mean: is it true that every decode of an encoded string will produce the same points ?

Or it is better to store the polygon on the server as multi points ?

Thanks for any help.

like image 587
Wajih Avatar asked Nov 01 '25 23:11

Wajih


1 Answers

If you take a look at the encode method that is used to encode a sequence of latitude/longitudes on the Google Maps Android API Utility Library you will see that it rounds the fifth decimal place:

long lat = Math.round(point.latitude * 1e5);
long lng = Math.round(point.longitude * 1e5);

From the Wikipedia, 0.00001 decimal degrees is equivalent to 1.1132 meters at equator.

Anyway, take into account that this is the behaviour now, and it's transparent to you, so you may not notice if the implementation changes to allow more precision or if the precision is more truncated. Thus, if the precision of the coordinates is important to you, you may want to store the coordinates as a list of points on your system.

like image 56
antonio Avatar answered Nov 04 '25 16:11

antonio