Distance between Long Lat coordinates using SQLITE

I have sqlite db with long and latin stores and I want to know the next 5 stores.

So the following code is working fine.

    if(sqlite3_prepare_v2(db, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {


    while (sqlite3_step(compiledStatement) == SQLITE_ROW) {

        NSString *branchStr = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)];
        NSNumber *fLat = [NSNumber numberWithFloat:(float)sqlite3_column_double(compiledStatement, 1)];
        NSNumber *fLong = [NSNumber numberWithFloat:(float)sqlite3_column_double(compiledStatement, 2)];

        NSLog(@"Address %@, Lat = %@, Long = %@", branchStr, fLat, fLong);
        CLLocation *location1 = [[CLLocation alloc] initWithLatitude:currentLocation.coordinate.latitude longitude:currentLocation.coordinate.longitude];
        CLLocation *location2 = [[CLLocation alloc] initWithLatitude:[fLat floatValue] longitude:[fLong floatValue]];

        NSLog(@"Distance i meters: %f", [location1 getDistanceFrom:location2]);
        [location1 release];
        [location2 release];
    }       
}

I know the distance from where I am in every store. My question is:

  • Is it better to return the distance back to sqlite string, I have the string when I go through the database. How should I do it? Am I using an UPDATE statement? Does anyone have some code to help me.

  • I can read sqlite into an array and then sort the array. Do you recommend this for the above approach? Is it more efficient?

Finally, if someone has the best way to get the next 5 stores, love to listen to him.

+3
2

SQL - SQL-. Google sqlite Haversine, .

:

http://www.thismuchiknow.co.uk/?p=71

+5

, . Deque-container, , 5, , . Deque. db 5 deque.

0

Source: https://habr.com/ru/post/1747465/


All Articles