6 ms·
I recently ran into a weird error concerning Lat/Lngs and floating point numbers. Google has a service for retrieving imagery from Maps, and you can even reques
by moron4hire 7y ago
I recently ran into a weird error concerning Lat/Lngs and floating point numbers. Google has a service for retrieving imagery from Maps, and you can even request that imagery have certain paths drawn on it. You encode those paths as part of your request URI, but if you have a lot of points, you could end up exceeding their maximum URI length restriction. So they also define a hashing system for compressing those points into a single value, which is defined here: https://developers.google.com/maps/documentation/utilities/polylinealgorithm https://developers.google.com/maps/documentation/utilities/p...
One of the things they don't mention is that the rounding step does not work as they expect for single-precision floats. You have to use double-precision floats to get the same results that they are demonstrating in the example.
They are asking for 5 values to the right of decimal points, which, with the maximum of 3 digits to the left of the decimal point, means a total of 8 significant digits. Single-precision floats should be good to 9 digits, but the rounding step is off by one when using singles.
The solution was to cast singles to doubles before performing the rounding. Which seems absurd.
Single-precision floats should be enough precision for lat/lngs anywhere on the Earth, for everything other than some applications in commercial-grade surveying. And if that is the job you're doing, you shouldn't be using Google Maps.