无聊写了个应用叫做Find my car,但是获取到的坐标一个是标准的gps坐标,另外一个就是上面的图吧的坐标。但是这个坐标直接在高德地图上标记却是错误的,于是就想办法看怎么转换下,不错这里直接有份源代码可以参考:猛击此处下载
这个项目引入了很多自定义的sqlite3的文件,其实没什么必要,改写一下就ok了。
#import
#define DBNAME @"gps.db"
//转换gps坐标为火星坐标
-(CLLocationCoordinate2D)zzTransGPS:(CLLocationCoordinate2D)yGps
{
NSString *database_path = [[NSHomeDirectory() stringByAppendingString:@"/Documents/"] stringByAppendingString:DBNAME];
if (sqlite3_open(database_path.UTF8String, &db) != SQLITE_OK) {
sqlite3_close(db);
NSLog(@"Open gps data failed!");
}
int TenLat=0;
int TenLog=0;
TenLat = (int)(yGps.latitude*10);
TenLog = (int)(yGps.longitude*10);
NSString *sql = [[NSString alloc]initWithFormat:@"select offLat,offLog from gpsT where lat=%d and log = %d",TenLat,TenLog];
NSLog(@"SQL command:%@", sql);
const char * sqlc= [sql UTF8String];
sqlite3_stmt* stmtL ;
if (sqlite3_prepare_v2(db, sqlc, -1, &stmtL, nil) != SQLITE_OK)
{
NSLog(@"SQl prepare failed %s",sqlite3_errmsg(db));
}
int offLat=0;
int offLog=0;
while (sqlite3_step(stmtL)==SQLITE_ROW)
{
offLat = sqlite3_column_int(stmtL, 0);
offLog = sqlite3_column_int(stmtL, 1);
}
yGps.latitude = yGps.latitude+offLat*0.0001;
yGps.longitude = yGps.longitude + offLog*0.0001;
return yGps;
}
需要从上面的项目中下载gps.db