I have blocks of data associated with latitude/longitude values. I’d like to create a lookup key/hash value from the latitude/longitude value so it can be used as a lookup into a map or something similar.
I’m using negative values for West and South… therefore 5W, 10S is represented as -5, -10 in the program.
I’d like to be able to get the latitude/longitude values back from the key value if possible.
The derived value MUST be some sort of integer value.
I’m using C/C++ 🙂
Thanks, I’ll be happy to answer any questions!
You could also encode it in nicely into a 64-bit integer using some bit manipulation
longitude ranges from -180 to 180 so needs a minimum of 9 bits.
lattitude rangs from -90 to +90 so needs a minimum of 8 bits.
minutes go from 0 to 60 so require 6 bits.
same for seconds.
9+12 = 21 bits for longitude and 20 bits for lattitude.
For subsecond precision you can then use 11 bit fixed point. this gives you accuracy down to a 2048th of a second.
SO to store a longitude or lattitude you could use a struct as follows