Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a formula to change a latitude and longitude into a single number?

Can you tell me if there is a formula to change a latitude and longitude into a single number?

I plan to use this for a database table in software that provides routing for deliveries. The table row would have that number as well as the postal address. The database table would be sorted in ascending numeric order so the software can figure out which address the truck would need to go to first, second etc.

Please can you respond showing VB or VB.Net syntax so I can understand how it works?

For example I would use the following numbers for the latitude and longitude: Lat = 40.71412890 Long = -73.96140740

Additional Information:

I'm developing an Android app using Basic4Android. Basic4Android uses a VB or VB.Net syntax with SQLite as the database.

Part of this app will have route planning. I want to use this number as the first column in an SQLite table and the other columns will be for the address. If I do a query within the app that sorts the rows in numerical ascending order, I will be able to figure out which postal address are closest to each other so it will take less time for me to go from house to house.

For example, if the numbers were: 194580, 199300, 178221

I can go to postal address 178221 then to 194580 and finally to 199300 and I won't need to take the long way around town to do my deliveries after they were sorted.

As an alternative, I would be happy if there was an easy way to call a web service that returns maybe a json response that has the single number if I send a postal address to the web site. Basic4Android does have http services that can send requests to a web site.

like image 347
Emad-ud-deen Avatar asked Nov 27 '11 12:11

Emad-ud-deen


People also ask

How do I convert latitude and longitude to numbers in Excel?

To get the latitude of the address in cell B2, use the formula = GetLatitude(B2) To get the longitude of the address in cell B2, use the formula = GetLongitude(B2) To get both the latitude and longitude of the address in cell B2, use the formula = GetCoordinates(B2)


1 Answers

A latitude an longitude, can both be represented as 4 byte integer, such that the coordinates has an accuracy of 3cm which is sufficent for most applications.

Steps to create one 8 byte value of type long from latitude and longitude:

1) convert lat and lon to int by: int iLat = lat * 1E7;
2) Use a 8 byte long value to store both 4 byte int.
set upper 4byte to latitude, and lower 4 to longitude.

Now you have a 8 byte long representing a point on world up to 3cm accuracy.

There are other, better solutions, such ones that maintain similar numbers for near locations, but these are more complex.

like image 130
AlexWien Avatar answered Sep 19 '22 02:09

AlexWien