I'm working on a little app that stores Placemarks specified by iOS devices, into a MySQL backend. When a device saves a new Placemark, it is INSERTed into the DB and the newly generated ID is sent back to the client. If another device attempts to save the same Placemark, the server needs to figure out that it already exists in the DB, and instead of INSERTing and generating a new ID, it needs to send back to the client the existing ID for that Placemark.
2 Placemarks are the same if they have identical:
- name
- latitude
- longitude
Therefore the server attempts to identify if the submitted Placemark already exists by issuing
SELECT id FROM Placemark WHERE name=x, latitude=y, longitude=x
- In iOS,
latitude
andlongitude
are in degrees and of typeCLLocationDegrees
as reported by<CoreLocation>
- In MySQL,
latitude
andlongitude
are defined asDOUBLE
The problem:
Precision is lost when storing coordinates, for instance:
latidude
of 50.09529561485427
is stored as 50.0952956148543
longitude
of -122.9893130423316
is stored as -122.989313042332
The question:
Can I use a different data type in MySQL so as to store each coordinate intact?
Notes:
- I can't store coordinates as
TEXT
orVARCHAR
because I need to be able to saySELECT placemarks coordinates BETWEEN x AND y
, or perform other arithmetic SELECTs - I can't use MySQL's spatial extensions because portability is an issue, and also because to my understanding, spatial data types are very slow when used as keys (and my use case requires SELECT by coordinates)
Any help appreciated