zl程序教程

您现在的位置是:首页 >  其它

当前栏目

GPS坐标 转 火星坐标

坐标 火星 GPS
2023-06-13 09:17:11 时间

无聊写了个应用叫做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

☆文章版权声明☆

* 网站名称:obaby@mars * 网址:https://h4ck.org.cn/ * 本文标题: 《GPS坐标 转 火星坐标》 * 本文链接:https://h4ck.org.cn/2014/09/gps%e5%9d%90%e6%a0%87-%e8%bd%ac-%e7%81%ab%e6%98%9f%e5%9d%90%e6%a0%87/ * 转载文章请标明文章来源,原文标题以及原文链接。请遵从 《署名-非商业性使用-相同方式共享 2.5 中国大陆 (CC BY-NC-SA 2.5 CN) 》许可协议。


分享文章:

相关文章:

  1. 浅谈iOS游戏的汉化
  2. Using NSTask in iOS Console Application
  3. 百度语音识别 语音唤醒失败
  4. GAppProxy被频繁重置
  5. HashAB for iOS 4.x
  6. OSX and iOS Kernel Programming
  7. theos Makefile
  8. libgpod-0.8.3 for windows
  9. T-PoT
  10. IOKit for iOS SDK 7.0