将地图坐标存储到sqlite数据库中

时间:2011-06-10 10:09:27

标签: iphone objective-c mkmapview

我看了很多用于将数据存储到sqlite中的示例代码,但它可以工作。我如何存储它 我想添加(newLocation.coordinate.latitude,newLocation.coordinate.longitude) 进入sqlite数据库。 我发现这个(newLocation.coordinate.latitude,newLocation.coordinate.longitude) 从这里

 -(void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{
    if (newLocation)
    {


        // make sure the old and new coordinates are different
        if ((oldLocation.coordinate.latitude != newLocation.coordinate.latitude) &&
            (oldLocation.coordinate.longitude != newLocation.coordinate.longitude))
        {    
            //I think Here will my sqlite query for storing the newLocation.coordinate.latitude and  newLocation.coordinate.longitude 
         //But I dont know how i store this location into the sqlite database.

         }
     }
}

我该怎么办。任何人都可以帮助我。

3 个答案:

答案 0 :(得分:2)

你可以使用这个声明......

sqlite3_bind_double(stmt,1,newLocation.coordinate.latitude);

答案 1 :(得分:0)

使用coredata会更容易,其他明智的尝试存储到plist。

答案 2 :(得分:0)

在我看来它非常简单,只是在其中创建了一个函数open sqlite db然后编写这段代码

NSString *update = [[NSString alloc] initWithFormat:@"INSERT OR REPLACE INTO table (longitude, latitude) VALUES ('32.333, 74.6655');"];



char * errorMsg;

    if (sqlite3_exec (database, [update UTF8String], NULL, NULL, &errorMsg) != SQLITE_OK)
    {
        NSAssert1(0, @"Error updating tables: %s", errorMsg);   
    }

    NSLog(@"Location Inserted");

`