Note that there are some explanatory texts on larger screens.

plurals
  1. PODistance Function for SQLite in iOS 5 is very slow
    primarykey
    data
    text
    <p>I have been using for a long time a C function that calculates the distance between coordinates in SQLLite.</p> <p>The thing is that for the very same database and different iOS devices (4 and 5) the time for executing the same query is 5 times longer when running iOS 5.</p> <p>Does anybody knows why?</p> <p>Here's the code for the distance:</p> <pre><code>static void distanceFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ // check that we have four arguments (lat1, lon1, lat2, lon2) assert(argc == 4); // check that all four arguments are non-null if (sqlite3_value_type(argv[0]) == SQLITE_NULL || sqlite3_value_type(argv[1]) == SQLITE_NULL || sqlite3_value_type(argv[2]) == SQLITE_NULL || sqlite3_value_type(argv[3]) == SQLITE_NULL) { sqlite3_result_null(context); return; } // get the four argument values double lat1 = sqlite3_value_double(argv[0]); double lon1 = sqlite3_value_double(argv[1]); double lat2 = sqlite3_value_double(argv[2]); double lon2 = sqlite3_value_double(argv[3]); // convert lat1 and lat2 into radians now, to avoid doing it twice below double lat1rad = DEG2RAD(lat1); double lat2rad = DEG2RAD(lat2); // apply the spherical law of cosines to our latitudes and longitudes, and set the result appropriately // 6378.1 is the approximate radius of the earth in kilometres sqlite3_result_double(context, (acos(sin(lat1rad) * sin(lat2rad) + cos(lat1rad) * cos(lat2rad) * cos(DEG2RAD(lon2) - DEG2RAD(lon1))) * 6378.1) * 1000); } </code></pre> <p>and here's a example on how I am using it:</p> <pre><code>Select distance(Latitude, Longitude,-22.89095,-47.05134) from TABLE </code></pre> <p>Please, any help will be very appreciated</p> <p>Thanks</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.
    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