MKMapView学习笔记
来源:互联网 发布:java电商项目经验 编辑:程序博客网 时间:2024/04/30 13:40
一.基本知识
iPhone可以使用CoreLocation框架确定他的物理位置,可以利用三种技术来实现该功能:GPS,WIFI定位和蜂窝基站三角网定位。但在程序中我们只需设定我们希望的精度级别,由CoreLocation决定采用哪种技术可以更好的满足我们的请求。
二.具体介绍
1.位置管理器
CLLocationManager *locationManager = [[CLLocationManager alloc] init];//创建位置管理器
locationManager.delegate=self;//设置代理
locationManager.desiredAccuracy=kCLLocationAccuracyBest;//指定需要的精度级别
locationManager.distanceFilter=1000.0f;//设置距离筛选器
[locationManager startUpdatingLocation];//启动位置管理器
2.位置管理器代理
主要的代理方法有两个
//确定当前位置和位置更新了时调用这个方法
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSString *latitudeString=[[NSString alloc] initWithFormat:@"%g",newLocation.coordinate.latitude];
//latitudeLabel.text=latitudeString;
[latitudeString release];
NSString *longitudeString=[[NSString alloc] initWithFormat:@"%g",newLocation.coordinate.longitude];
//longitudeLabel.text=longitudeString;
[longitudeString release];
}
//位置查询遇到错误时调用这个方法
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
NSString *errorType = (error.code == kCLErrorDenied) ?
@"Access Denied" : @"Unknown Error";
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Error getting Location"
message:errorType
delegate:nil
cancelButtonTitle:@"Okay"
otherButtonTitles:nil];
[alert show];
[alert release];
}
附一张截图:
- MKMapView学习笔记
- MKMapView的学习
- MKMapView的基础学习
- MKMapView 学习总结(一)
- MKMapView 学习总结(二)
- MKMapView 学习总结(三)
- MKMapView 学习总结(四)
- MKMapView 学习总结(五)
- MKMapView
- IOS开发学习:MKMapView自定义CalloutView
- 1天学习1个类库 MKMapView Overlay示例
- MKMapView用法
- iphone--MKMapView
- iphone MKMapView
- MKMapView展示
- MKMapView 相关
- MKMapView用法
- MKMapView小结
- 一种自增列为主键时的并发访问问题——讨论Identity值访问
- GNU/CPIO 学习小结
- 广播的发送和接收
- 2步成为一位伟大的开发者
- HDOJ 1013
- MKMapView学习笔记
- OneNote 发送至 CSDN
- Drawable简单使用
- WINDOWS 逻辑坐标 设备坐标 屏幕坐标 客户区坐标
- Socket编程基础范例
- RegQueryValueEx函数返回234错误解决方法
- 重写Ext.MessageBox.confirm中文按钮名称
- 彻底搞定C指针---指向指针的指针
- DAY 5