Note that there are some explanatory texts on larger screens.

plurals
  1. POPrecision lost when storing CLLocationDegrees in MySQL
    primarykey
    data
    text
    <p>I'm working on a little app that stores <em>Placemarks</em> specified by iOS devices, into a MySQL backend. When a device saves a new <em>Placemark</em>, 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 <em>Placemark</em>, 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.</p> <p>2 <em>Placemarks</em> are the same if they have identical:</p> <ul> <li>name</li> <li>latitude</li> <li>longitude</li> </ul> <p>Therefore the server attempts to identify if the submitted Placemark already exists by issuing </p> <blockquote> <p>SELECT id FROM Placemark WHERE name=x, latitude=y, longitude=x</p> </blockquote> <ul> <li>In iOS, <code>latitude</code> and <code>longitude</code> are in degrees and of type <code>CLLocationDegrees</code> as reported by <code>&lt;CoreLocation&gt;</code></li> <li>In MySQL, <code>latitude</code> and <code>longitude</code> are defined as <code>DOUBLE</code></li> </ul> <p><br> <strong>The problem:</strong> <br>Precision is lost when storing coordinates, for instance: <br><code>latidude</code> of <code>50.09529561485427</code> is stored as <code>50.0952956148543</code> <br><code>longitude</code> of <code>-122.9893130423316</code> is stored as <code>-122.989313042332</code></p> <p><strong>The question:</strong> <br>Can I use a different data type in MySQL so as to store each coordinate intact?</p> <p><strong>Notes:</strong></p> <ul> <li>I can't store coordinates as <code>TEXT</code> or <code>VARCHAR</code> because I need to be able to say <code>SELECT placemarks coordinates BETWEEN x AND y</code>, or perform other arithmetic SELECTs</li> <li>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)</li> </ul> <p>Any help appreciated</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload