在iOS应用中使用GPS
来源:互联网 发布:linux多进程服务器 编辑:程序博客网 时间:2024/05/29 12:24
测试代码如下:
// LocationViewCtrl.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface LocationViewCtrl : UIViewController <CLLocationManagerDelegate>{
CLLocationManager *man;
}
@property(nonatomic, retain) CLLocationManager *man;
@end
LocationViewCtrl.m
#import "LocationViewCtrl.h"
#import <CoreLocation/CoreLocation.h>
@implementation LocationViewCtrl
@synthesize man;
- (void)viewDidLoad {
[super viewDidLoad];
man = [[CLLocationManager alloc] init];
// 如果可以利用本地服务时
if([man locationServicesEnabled]){
// 接收事件的实例
man.delegate = self;
// 发生事件的的最小距离间隔(缺省是不指定)
man.distanceFilter = kCLDistanceFilterNone;
// 精度 (缺省是Best)
man.desiredAccuracy = kCLLocationAccuracyBest;
// 开始测量
[man startUpdatingLocation];
}
}
// 如果GPS测量成果以下的函数被调用
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation{
// 取得经纬度
CLLocationCoordinate2D coordinate = newLocation.coordinate;
CLLocationDegrees latitude = coordinate.latitude;
CLLocationDegrees longitude = coordinate.longitude;
// 取得精度
CLLocationAccuracy horizontal = newLocation.horizontalAccuracy;
CLLocationAccuracy vertical = newLocation.verticalAccuracy;
// 取得高度
CLLocationDistance altitude = newLocation.altitude;
// 取得时刻
NSDate *timestamp = [newLocation timestamp];
// 以下面的格式输出 format: <latitude>, <longitude>> +/- <accuracy>m @ <date-time>
NSLog([newLocation description]);
// 与上次测量地点的间隔距离
if(oldLocation != nil){
CLLocationDistance d = [newLocation getDistanceFrom:oldLocation];
NSLog([NSString stringWithFormat:@"%f", d]);
}
}
// 如果GPS测量失败了,下面的函数被调用
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error{
NSLog([error localizedDescription]);
}
...
测量精度有以下几类,精度越高越消耗电力。
kCLLocationAccuracyNearestTenMeters10mkCLLocationAccuracyHundredMeters100mkCLLocationAccuracyKilometer1kmkCLLocationAccuracyThreeKilometers3km因为在模拟器上不能设置经纬度,所以只能在实际设备中测试你的GPS程序。
- 在 iOS 应用中使用 GPS
- 在iOS应用中使用GPS
- 在 iOS 应用中使用 GPS
- iOS中GPS定位
- 在gps构架中
- GPS 在航空运输中的应用
- 在 WSI 中使用 C++ 开发 iOS 应用
- 如何在iOS应用中使用自定义字体
- 在iOS应用中使用字体图标及制作字体库
- 使用ionic2移动应用在IOS中遇到的问题
- iPhone开发进阶(10)--- 在程序中使用GPS
- GPS在Android的使用
- 在树莓派上使用GPS模块
- 透视投影变换在GPS导航中的应用
- 透视投影变换在GPS导航中的应用
- Android Location在GPS中的应用(一)
- Android Location在GPS中的应用(二)
- KalmanFilter在GPS定位中的应用
- Linux进程的实际用户ID和有效用户ID
- windows 2003 server IIS权限设置
- 分享一个异步发送邮件的类
- Shell scripting 1 - introduction
- 获得文件头编辑框中多行文本
- 在iOS应用中使用GPS
- 黑马程序员-委托
- VC:利用 CPtrArray 类保存图像
- 模拟设计工具大比拼
- js随笔一
- mongodb 更新操作
- CSS定位技术
- [转载]UIUC同学Jia-Bin Huang收集的计算机视觉代码合集
- C#编写Windows服务的基本过程