Wednesday, February 9, 2011

MapKit Lat/Long "Errors" and Decimal Precision

Benchmark DX1095photo © 2008 Chuck Coker | more info (via: Wylio)
After the recent release of our MapKit plugin for TapLynx we got an email from someone who wanted to know why every point on their map was about 2 miles (3.2 km) to the East. After we got over the initial panic and fear that every developer gets when a piece of code they released to the public might have a bug we started to wonder about what could have caused the issue and why things looked fine on our machine.

As we looked at it more, we wondered if decimal precision was the issue.

I found this that talks about translating each decimal place of precision into meters of offset.

Here are some test we ran modifying the precision for the location of Elvis Presley's Graceland mansion. The address we fed into was 3765 Elvis Presley Blvd, Memphis TN 38116. This caused geocoder to give us a decimal latitude of 35.045988, and a longitude of -90.024982. When we plug these numbers into our MapKit plugin we get a nice pin right at the front gates.

Next we made a number of duplicates of the entry and for each one took off one decimal place (e.g. 35.045988, 35.04598, 35.0459, 35.045, 35.04, 35.0). To make it easier to see the effect we did latitude separately from longitude. For each one of these maps, we have six pins drawn. In both cases, the first few pins are effectively in the same place so we know that -90.024982 and -90.02498 are pretty precise measurements for an address. However, -90 is pretty far over to the East. Similarly, as we decrease the precision of the latitude measurements, our pins head South down Elvis Presley Boulevard and 35.045988 is pretty far from 35.
Changing Longitude
Changing Latitude

So, at least to us, this says, five or six decimal places are needed for a good street address. Fortunately, MapKit uses double float numbers for the latitude and longitude values. That means we have plenty of decimal places to work with.

Since the Earth isn't a perfect sphere and since some location points will be unaffected by added precision (i.e. 35.5 = 35.50000000) we expect that changing precision has different impacts on map points depending on the location of the map point.

No comments:

Post a Comment