这个写的公共类叫做:GPScombineClass类主要展示GPS位置的定位,GPS坐标的获取,然后从手机坐标转换成火星坐标,继而在需要的情况下,由火星转百度 ,百度转火星的详细算法;

 

在GPScombineClass.h中

#import <Foundation/Foundation.h>

#import <CoreLocation/CoreLocation.h>

#import "CSqlite.h"

#import <MapKit/MapKit.h>

@interface GPScombineClass : NSObject<MKMapViewDelegate>{

CLLocationManager *locationManager;

CSqlite *m_sqlite;

UILabel *m_locationName;

MKMapView *mainMapView;

@public CLLocationCoordinate2D baidulocation;

CLLocationCoordinate2D deleeverLocation;

}

-(void)OpenGPSmapView;

//在地图上放上自己的位置--外接接口

-(void)setMyMapPonitByMKMapView:(MKMapView *)MyMap;

@end

@interface POI : NSObject <MKAnnotation> {

CLLocationCoordinate2D coordinate;

NSString *subtitle;

NSString *title;

}

@property (nonatomic,readonly) CLLocationCoordinate2D coordinate;

@property (nonatomic,retain) NSString *subtitle;

@property (nonatomic,retain) NSString *title;

-(id) initWithCoords:(CLLocationCoordinate2D) coords;

@end

在GPScombineClass.m中

#import "GPScombineClass.h"

const double x_pi = 3.14159265358979324 * 3000.0 / 180.0;

@implementation GPScombineClass

-(void)OpenGPSmapView{

m_sqlite = [[CSqlite alloc]init];

[m_sqlite openSqlite];

if ([CLLocationManager locationServicesEnabled]) { // 检查定位服务是否可用

locationManager = [[CLLocationManager alloc] init];

locationManager.delegate = self;

locationManager.distanceFilter=0.5;

locationManager.desiredAccuracy = kCLLocationAccuracyBest;

[locationManager startUpdatingLocation]; // 开始定位

}

NSLog(@"GPS 启动");

}

// 定位成功时调用

- (void)locationManager:(CLLocationManager *)manager

didUpdateToLocation:(CLLocation *)newLocation

fromLocation:(CLLocation *)oldLocation

{

CLLocationCoordinate2D mylocation = newLocation.coordinate;//手机GPS

mylocation = [self zzTransGPS:mylocation];///转换成火星GPS

deleeverLocation=mylocation;

baidulocation=[self hhTrans_bdGPS:mylocation];//转换成百度地图

/*

//显示火星坐标

[self SetMapPoint:mylocation MKMapView:mainMapView];

/////////获取位置信息

CLGeocoder *geocoder = [[CLGeocoder alloc] init];

[geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray* placemarks,NSError *error)

{

if (placemarks.count >0   )

{

CLPlacemark * plmark = [placemarks objectAtIndex:0];

NSString * country = plmark.country;

NSString * city    = plmark.locality;

NSLog(@"%@-%@-%@",country,city,plmark.name);

self->m_locationName.text =plmark.name;

NSLog(@"%@",self->m_locationName);

}

NSLog(@"%@",placemarks);

}];

//[geocoder release];

*/

}

// 定位失败时调用

- (void)locationManager:(CLLocationManager *)manager

didFailWithError:(NSError *)error {

NSLog(@"定位失败");

}

//把手机GPS坐标转换成火星坐标 (google坐标)

-(CLLocationCoordinate2D)zzTransGPS:(CLLocationCoordinate2D)yGps

{

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);

sqlite3_stmt* stmtL = [m_sqlite NSRunSql:sql];

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;

}

//在地图上放上自己的位置--外接接口

-(void)setMyMapPonitByMKMapView:(MKMapView *)MyMap{

//显示火星坐标

[self SetMapPoint:deleeverLocation MKMapView:MyMap];

MyMap=mainMapView;

}

//在地图上放上自己的位置

-(void)SetMapPoint:(CLLocationCoordinate2D)myLocation MKMapView:(MKMapView *)mapView

{

//    POI* m_poi = [[POI alloc]initWithCoords:myLocation];

//

//    [mapView addAnnotation:m_poi];

MKCoordinateRegion theRegion = { {0.0, 0.0 }, { 0.0, 0.0 } };

theRegion.center=myLocation;

[mapView setZoomEnabled:YES];

[mapView setScrollEnabled:YES];

theRegion.span.longitudeDelta = 0.01f;

theRegion.span.latitudeDelta = 0.01f;

[mapView setRegion:theRegion animated:YES];

}

//把火星坐标转换成百度坐标

-(CLLocationCoordinate2D)hhTrans_bdGPS:(CLLocationCoordinate2D)fireGps

{

CLLocationCoordinate2D bdGps;

double huo_x=fireGps.longitude;

double huo_y=fireGps.latitude;

double z = sqrt(huo_x * huo_x + huo_y * huo_y) + 0.00002 * sin(huo_y * x_pi);

double theta = atan2(huo_y, huo_x) + 0.000003 * cos(huo_x * x_pi);

bdGps.longitude = z * cos(theta) + 0.0065;

bdGps.latitude = z * sin(theta) + 0.006;

return bdGps;

}

#pragma mark 显示商品信息

#pragma mark

-(void)showPurchaseOnMapByLocation:(CLLocationCoordinate2D)baiduGPS MKMapView:(MKMapView*)myMapView{

CLLocationCoordinate2D googleGPS;

googleGPS=[self hhTrans_GCGPS:baiduGPS];//转换为百度

[self SetPurchaseMapPoint:googleGPS MKMapView:myMapView];

}

//把百度地图转换成谷歌地图--火星坐标

-(CLLocationCoordinate2D)hhTrans_GCGPS:(CLLocationCoordinate2D)baiduGps

{

CLLocationCoordinate2D googleGps;

double bd_x=baiduGps.longitude - 0.0065;

double bd_y=baiduGps.latitude - 0.006;

double z = sqrt(bd_x * bd_x + bd_y * bd_y) - 0.00002 * sin(bd_y * x_pi);

double theta = atan2(bd_y, bd_x) - 0.000003 * cos(bd_x * x_pi);

googleGps.longitude = z * cos(theta);

googleGps.latitude = z * sin(theta);

return googleGps;

}

-(void)SetPurchaseMapPoint:(CLLocationCoordinate2D)myLocation MKMapView:(MKMapView *)mapView

{

POI* m_poi = [[POI alloc]initWithCoords:myLocation];

[mapView addAnnotation:m_poi];

MKCoordinateRegion theRegion = { {0.0, 0.0 }, { 0.0, 0.0 } };

theRegion.center=myLocation;

[mapView setZoomEnabled:YES];

[mapView setScrollEnabled:YES];

theRegion.span.longitudeDelta = 0.01f;

theRegion.span.latitudeDelta = 0.01f;

[mapView setRegion:theRegion animated:YES];}

@end

ISO GPS定位,坐标转换以及如何显示的更多相关文章

  1. GPS(2)关于位置的3个示例,实时获取GPS定位数据,求两个经纬点距离,邻近某个区域圆时警告

    实时获取GPS定位数据 import android.app.Activity; import android.content.Context; import android.location.Loc ...

  2. GPS定位学习笔记

    ********************************* GPS定位简介 ********************************** 1. iOS SDK提供两个框架来实现位置服务 ...

  3. 与众不同 windows phone (20) - Device(设备)之位置服务(GPS 定位), FM 收音机, 麦克风, 震动器

    原文:与众不同 windows phone (20) - Device(设备)之位置服务(GPS 定位), FM 收音机, 麦克风, 震动器 [索引页][源码下载] 与众不同 windows phon ...

  4. Android GPS定位测试(附效果图)

    今天因为工作需要,把以前编写的一个GPS测试程序拿出来重新修改了一下.这个程序说起来有些历史了,是我11年编写的,那时候学了Android开发没多久,算是一个实验性的作品.现在工作需要,重新拿出来修整 ...

  5. Android GPS定位测试(附效果图)

    今天因为工作需要,把以前编写的一个GPS测试程序拿出来重新修改了一下.这个程序说起来有些历史了,是我11年编写的,那时候学了Android开发没多久,算是一个实验性的作品.现在工作需要,重新拿出来修整 ...

  6. 手机版的百度map封装,使用gps定位

    代码如下,包自己引 包参考 一个百度MAP导航的基础封装 使用的是浏览器调用gps定位 修改了标注的大小 效果如图: 代码...... <!DOCTYPE html> <html&g ...

  7. Android---58---初学GPS定位

    GPS英文是Global Positioning System 全球定位系统的简称. Android为GPS功能支持专门提供了一个LocationManager,位置管理器.全部GPS定位相关的服务. ...

  8. GPS定位 测试

    public class MainActivity extends Activity { private final String TAG = "BX"; private Loca ...

  9. Android中GPS定位的简单应用

    在Android中通过GPS获得当前位置,首先要获得一个LocationManager实例,通过该实例的getLastKnownLocation()方法获得第一个的位置,该方法的说明如下: void ...

随机推荐

  1. linux tftp 服务

    TFTP(Trivial File Transfer Protocol)是基于UDP协议开发,用来在客户机与server之间进行简单文件传输的协议,提供不复杂.开销不大的文件传输服务. 一.改动/et ...

  2. Dom4j完整教程,操作XML教程

    目录 1.DOM4J简介 2.XML文档操作1 2.1.读取XML文档: 2.2.获取根节点 2.3.. 新增一个节点以及其下的子节点与数据 2.4. 写入XML文件 2. 5. 遍历xml节点 2. ...

  3. Spark ML 几种 归一化(规范化)方法总结

    规范化,有关之前都是用 python写的,  偶然要用scala 进行写, 看到这位大神写的, 那个网页也不错,那个连接图做的还蛮不错的,那天也将自己的博客弄一下那个插件. 本文来源 原文地址:htt ...

  4. iOS中CGRectDividede中布局用法

    - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typica ...

  5. [转载]JDBC/Spring/MyBatis性能比较

    原文地址:JDBC/Spring/MyBatis性能比较作者:tom_lt 测试目的: 比较JDBC,SpringJdbc和MyBatis的性能.   测试用例: 1. 查询:查询一张10000条数据 ...

  6. DPDK架构与特点(转)

    from:http://www.cnblogs.com/mylinuxer/p/4277676.html DPDK架构与特点 当年在某公司实习的时候,当时老大给了我一份DPDK的文档,说是将来很有用, ...

  7. 树莓派进阶之路 (026) - 基于 Samba 实现 NAS 系统

    摆弄了几天Raspberry Pi,在搞定了无线网络.FTP服务之后,打算更进一步,通过Samba实现NAS系统与PC共享文件.需要安装的软件:sudo apt-get install samba s ...

  8. 对于“Newtonsoft.Json”已拥有为“NETStander.Library”定义的依赖项,解决办法

    问题描述: 在使用visual studio中的NuGet包管理下载程序时,有时会出现-对于“Newtonsoft.Json”已拥有为“NETStander.Library”定义的依赖项,这样的错误. ...

  9. 【Android】详解Android的menu菜单

    在软件应用过程中,菜单的存在是必不可少的,我这次讲一下,我对android菜单的一个基础做法吧 Android的菜单分为三种类型:选项菜单(Option Menu).上下文菜单(Context Men ...

  10. 解决安装Egit时Egit Mylyn和org.eclipse.team.core报错

    为了让Aptana支持GitHub,需要安装Egit,但在的时候碰到两个错误,一个是关于缺少EGit Mylyn另一个是缺少org.eclipse.egit.import.feature.group. ...