Hi All,
Just wanted to share a formula I created to convert latitude and longitude into Google Maps Plus Codes. If you are not familiar with Plus Codes, check out this documentation.
The benefits to the plus code are:
Every location on earth can have a mailing address
The encoding of 10 characters plus “+” character is much more efficient in terms of number of bytes than latitude and longitude, which to represent the same level of specificity would need to consist of two floating point decimal numbers of 10 or even more decimal places specificity, requiring more than double the number of bytes, and a tuple type representation instead of a simple string primitive.
Plus codes can be used in filenames easily because they don’t use reserved characters.
Plus codes are compressible—each additional character adds another level of specificity, similar to the decimal place system, so if you have millions of plus codes you are storing, and you remove two characters from the end, you save on 25% of that data, at the cost of a just little bit of specificity.
No confusion over direction (NSEW) or positive/negative.
Given a regional or local landmark, plus codes can be compressed even more—for example, given a cell tower location, you probably only need 2-4 characters for a location, which can be located within the known larger plus code region of a cell tower—or you can use a landmark, a city, or county, etc.
There are many important uses, for example, addressing homes that don’t have streets or consistently named streets, especially in 3rd world countries or low-population density areas.
Even now you can search Google Maps using plus codes, just as you can with lat & lon. Anyway here are the formulas, which in the first, take two separate Latitude and Longitude fields, and in the second, a combined Location (ie latitude and longitude separated by a comma and/or space):
#1 (two separate latitude & longitude fields)
IF(AND(Latitude,Longitude),SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(CONCATENATE("("&FLOOR(MOD(FLOOR((Latitude+90)*8000)/POWER(20,4),20))&"]","2"&FLOOR(MOD(FLOOR((Longitude+180)*8000)/POWER(20,4),20))&"]","2"&FLOOR(MOD(FLOOR((Latitude+90)*8000)/POWER(20,3),20))&"]","2"&FLOOR(MOD(FLOOR((Longitude+180)*8000)/POWER(20,3),20))&"]","2"&FLOOR(MOD(FLOOR((Latitude+90)*8000)/POWER(20,2),20))&"]","2"&FLOOR(MOD(FLOOR((Longitude+180)*8000)/POWER(20,2),20))&"]","2"&FLOOR(MOD(FLOOR((Latitude+90)*8000)/POWER(20,1),20))&"]","2"&FLOOR(MOD(FLOOR((Longitude+180)*8000)/POWER(20,1),20))&"]","+","&"&FLOOR(MOD(FLOOR((Latitude+90)*8000)/POWER(20,0),20))&"]","2"&FLOOR(MOD(FLOOR((Longitude+180)*8000)/POWER(20,0),20))&"]"),"00]","2"),")1]","3"),")2]","4"),")3]","5"),")4]","6"),")5]","7"),")6]","8"),")7]","9"),")8]","C"),")9]","F"),")10]","G"),",11]","H"),",12]","J"),",13]","M"),",14]","P"),",15]","Q"),",16]","R"),",17]","V"),",18]","W"),",19]","X"))
#2 (one combined latitude & longitude field)
IF(Location,SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(CONCATENATE("("&FLOOR(MOD(FLOOR((LEFT(SUBSTITUTE({Location}," ",""),FIND(',',SUBSTITUTE({Location}," ",""))-1)+90)*8000)/POWER(20,4),20))&"]","2"&FLOOR(MOD(FLOOR((MID(SUBSTITUTE({Location}," ",""),FIND(',',SUBSTITUTE({Location}," ",""))+1,LEN(SUBSTITUTE({Location}," ","")))+180)*8000)/POWER(20,4),20))&"]","2"&FLOOR(MOD(FLOOR((LEFT(SUBSTITUTE({Location}," ",""),FIND(',',SUBSTITUTE({Location}," ",""))-1)+90)*8000)/POWER(20,3),20))&"]","2"&FLOOR(MOD(FLOOR((MID(SUBSTITUTE({Location}," ",""),FIND(',',SUBSTITUTE({Location}," ",""))+1,LEN(SUBSTITUTE({Location}," ","")))+180)*8000)/POWER(20,3),20))&"]","2"&FLOOR(MOD(FLOOR((LEFT(SUBSTITUTE({Location}," ",""),FIND(',',SUBSTITUTE({Location}," ",""))-1)+90)*8000)/POWER(20,2),20))&"]","2"&FLOOR(MOD(FLOOR((MID(SUBSTITUTE({Location}," ",""),FIND(',',SUBSTITUTE({Location}," ",""))+1,LEN(SUBSTITUTE({Location}," ","")))+180)*8000)/POWER(20,2),20))&"]","2"&FLOOR(MOD(FLOOR((LEFT(SUBSTITUTE({Location}," ",""),FIND(',',SUBSTITUTE({Location}," ",""))-1)+90)*8000)/POWER(20,1),20))&"]","2"&FLOOR(MOD(FLOOR((MID(SUBSTITUTE({Location}," ",""),FIND(',',SUBSTITUTE({Location}," ",""))+1,LEN(SUBSTITUTE({Location}," ","")))+180)*8000)/POWER(20,1),20))&"]","+","&"&FLOOR(MOD(FLOOR((LEFT(SUBSTITUTE({Location}," ",""),FIND(',',SUBSTITUTE({Location}," ",""))-1)+90)*8000)/POWER(20,0),20))&"]","2"&FLOOR(MOD(FLOOR((MID(SUBSTITUTE({Location}," ",""),FIND(',',SUBSTITUTE({Location}," ",""))+1,LEN(SUBSTITUTE({Location}," ","")))+180)*8000)/POWER(20,0),20))&"]"),"00]","2"),")1]","3"),")2]","4"),")3]","5"),")4]","6"),")5]","7"),")6]","8"),")7]","9"),")8]","C"),")9]","F"),")10]","G"),",11]","H"),",12]","J"),",13]","M"),",14]","P"),",15]","Q"),",16]","R"),",17]","V"),",18]","W"),",19]","X"))
Example input/output:
Input: 37.78239612266476, -122.40520883383574
(Airtable HQ)
Output: 849VQHJV+XW
(try searching this code on Google Maps)
That’s all, cheers!