google / open-location-code

Open Location Code is a library to generate short codes, called "plus codes", that can be used as digital addresses where street addresses don't exist.
https://plus.codes
Apache License 2.0
4.06k stars 472 forks source link

Unable to obtain exact coordinate (5 decimal) using normal PlusCode #429

Closed ArmstrongAppollo closed 3 years ago

ArmstrongAppollo commented 3 years ago

Any idea how to obtain an 'Extra Precise' PlusCode using this api?

I managed to get the 12 alphanumeric (with plus sign) using an add-on in Google Spreadsheet.

But I can only obtain a 'Normal' PlusCode with this api..

Hope someone can help. Thanks!

bocops commented 3 years ago

Can you clarify what exactly you are trying to achieve, using what language? A code example that doesn't work might help.

ArmstrongAppollo commented 3 years ago

Hi bocops, my website is developed in PHP and when I search using 5 decimal coordinate, the result is close to the search but not exactly the coordinate.

For example, I search for 0.67416, 23.47314 and the result is 0.67419°, 23.47319°. I guess it is caused by the PlusCode rounding. image

As I double checked from Google Spreadsheet, minor 0.00001 difference in coordinate won't change the PlusCode in normal conversion: image

But when I select 'Extra Precise' conversion, the PlusCode actually is different: image

So I'm thinking if any chance I can get 'Extra Precise' conversion using the same API.

bocops commented 3 years ago

I see. The underlying issue here might be that all plus codes refer to an area, not to an exact location. If lat/long coordinates are encoded into a plus code, then the resulting plus code is decoded again, the resulting coordinates are typically those of the center of the area.

For what it's worth, the area of a 10-digit area ("XXXXXXXX+XX", as used in your first example image) is roughly 14m x 14m or less for a plus code on Earth. Because the Moon has a circumference of about 1/4th, the area size should be roughly 3.5m x 3.5m over there, which is probably small enough for most usecases already. Each additional digit added to this code splits the area into a 4x5 grid, which means roughly 1m precision for an 11-digit code on the Moon.

The official API reference mentions that the encode method should have an optional length parameter - and I believe current consensus is that only lengths 10 and 11 are useful enough to be supported across all implementations, although I'm not sure if this is codified anywhere. So, if length 12 (or "extra precise", which I don't recognize as regularly used terminology) doesn't work, try 11.

ArmstrongAppollo commented 3 years ago

Awesome explanation! I just tried length 11 (or "precise", as termed by plus-codes-publisher). Unfortunately, the result is still unfavorable as 3 different coordinates are still sharing the same PlusCode: image

So I think the only way to obtain exact coordinate from a specific Plus Code is to decode from 12 characters. Will definitely try it. Thanks!

ArmstrongAppollo commented 3 years ago