Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Lat/Lon to Integer

A service that I'm consuming requires that I pass it the lat/lon for an address as integers. Currently, my lat/lon's are stored as doubles:

double lat = 38.898748;
double lon = -77.037684;

I've exhausted my Google-fu and can't find a method for converting lat/lon to an integer representation. Any help would be appreciated.

like image 683
James Hill Avatar asked Nov 07 '11 17:11

James Hill


3 Answers

Sometimes it is simple, just multiply by 1 million.

Multiply by .000001 to convert back.

Granted this assumes you only want precision to the 6th decimal.

like image 109
keithwarren7 Avatar answered Oct 10 '22 20:10

keithwarren7


You need to know what Geodetic System you're using and what the API expects. E.g. WGS84, NAD83, OSGB36, ED50... (Example: Google Earth uses WGS84)

If they need an integer then they're probably using something different from Google and other providers. Chances are that rounding a a double or some other integer conversion will not work. You need the Geodetic System information and then make the conversion between the two values.

like image 9
Paul Sasik Avatar answered Oct 10 '22 19:10

Paul Sasik


The only way I can see this happening is if you shift the decimal point.

int lat = (int)(38.898748 * 1000000.0);
int lon = (int)(-77.037684 * 1000000.0);
like image 4
ChaosPandion Avatar answered Oct 10 '22 19:10

ChaosPandion