IOS之地图和定位应用开发
2012-12-25 15:35
495 查看
地图开发一般过程
第一步 定位
CLLocationManagerDelegate是定位服务的委托,常用的位置变化回调方法是:
locationManager:didUpdateToLocation:fromLocation: locationManager:didFailWithError:
CLLocationManager 是的startUpdatingLocation方法启动所有定位硬件,对应的方法是stopUpdatingLocation,通过调用该方法关闭定位服务器更新,为了省电必须在不用的时候调用该方法关闭定位服务。
CLLocationManagerDelegate是定位服务委托。
MKMapViewDelegate是地图视图委托,主要方法:
-mapView:viewForAnnotation:
-mapViewDidFailLoadingMap:withError:
MKReverseGeocoderDelegate是给地理坐标获得标志点信息的委托,用于地理信息编码(即:从坐标获得地点获得信息),主要委托方法:
– reverseGeocoder:didFindPlacemark:
– reverseGeocoder:didFailWithError:
成功时候调用-reverseGeocoder:didFindPlacemark:
失败时候调用-reverseGeocoder:didFailWithError:
MKMapViewDelegate
是地图视图委托对象
[mapView addAnnotation:annotation]; 为地图添加标注,该方法将会触发mapView:viewForAnnotation:方法回调。
信息获取后 用 [mapView addAnnotation:annotation]; 系统会调用
- mapView:viewForAnnotation:为地图设置标注时候回调方法。
-mapViewDidFailLoadingMap:withError:地图加载错误时候回调方法。
作为地图标注对象实现MKAnnotation协议是必须的,只有实现该协议才能使该类成为标注类。实现NSCoding协议是可选的,实现该协议可以使标注对象能够复制。 里面的属性有哪些要看你自己的需要。
title
和subtitle 是MKAnnotation协议要求实现的方法。
//经度,纬度
CLLocationCoordinate2D coordinate2d = CLLocationCoordinate2DMake(40.034827, 116.311836);
//缩放比例
MKCoordinateSpan span = MKCoordinateSpanMake(0.1, 0.1);
MKCoordinateRegion region = MKCoordinateRegionMake(coordinate2d, span);
MyAnnotation* annotation = [[MyAnnotation alloc] initWithTitle:@"beijing" subTitle:@"haishibeijing"coordinate:coordinate2d];
[_mapView addAnnotation:annotation];
[annotation release];
clManager=[[CLLocationManager alloc] init];
//移动5米定位一次
clManager.distanceFilter = 5;
//定位的精准度
clManager.desiredAccuracy = kCLLocationAccuracyBest;
clManager.delegate = self;
[clManager startUpdatingLocation];
第一步 定位
CLLocationManagerDelegate是定位服务的委托,常用的位置变化回调方法是:
locationManager:didUpdateToLocation:fromLocation: locationManager:didFailWithError:
CLLocationManager 是的startUpdatingLocation方法启动所有定位硬件,对应的方法是stopUpdatingLocation,通过调用该方法关闭定位服务器更新,为了省电必须在不用的时候调用该方法关闭定位服务。
CLLocationManagerDelegate是定位服务委托。
MKMapViewDelegate是地图视图委托,主要方法:
-mapView:viewForAnnotation:
-mapViewDidFailLoadingMap:withError:
MKReverseGeocoderDelegate是给地理坐标获得标志点信息的委托,用于地理信息编码(即:从坐标获得地点获得信息),主要委托方法:
– reverseGeocoder:didFindPlacemark:
– reverseGeocoder:didFailWithError:
成功时候调用-reverseGeocoder:didFindPlacemark:
失败时候调用-reverseGeocoder:didFailWithError:
MKMapViewDelegate
是地图视图委托对象
[mapView addAnnotation:annotation]; 为地图添加标注,该方法将会触发mapView:viewForAnnotation:方法回调。
信息获取后 用 [mapView addAnnotation:annotation]; 系统会调用
- mapView:viewForAnnotation:为地图设置标注时候回调方法。
-mapViewDidFailLoadingMap:withError:地图加载错误时候回调方法。
作为地图标注对象实现MKAnnotation协议是必须的,只有实现该协议才能使该类成为标注类。实现NSCoding协议是可选的,实现该协议可以使标注对象能够复制。 里面的属性有哪些要看你自己的需要。
title
和subtitle 是MKAnnotation协议要求实现的方法。
//经度,纬度
CLLocationCoordinate2D coordinate2d = CLLocationCoordinate2DMake(40.034827, 116.311836);
//缩放比例
MKCoordinateSpan span = MKCoordinateSpanMake(0.1, 0.1);
MKCoordinateRegion region = MKCoordinateRegionMake(coordinate2d, span);
MyAnnotation* annotation = [[MyAnnotation alloc] initWithTitle:@"beijing" subTitle:@"haishibeijing"coordinate:coordinate2d];
[_mapView addAnnotation:annotation];
[annotation release];
clManager=[[CLLocationManager alloc] init];
//移动5米定位一次
clManager.distanceFilter = 5;
//定位的精准度
clManager.desiredAccuracy = kCLLocationAccuracyBest;
clManager.delegate = self;
[clManager startUpdatingLocation];
相关文章推荐
- IOS之地图和定位应用开发
- iOS地图和定位的应用开发
- IOS之地图和定位应用开发
- IOS使用内置地图,定位应用开发
- IOS之地图和定位应用开发
- IOS之地图和定位应用开发
- IOS之地图和定位应用开发
- IOS之地图和定位应用开发
- 判断一个坐标点是否在一个无规则的多边形内 (iOS定位服务与地图应用开发:高德地图开发)
- iOS之地图和定位应用开发
- iOS学习笔记–11 IOS之地图和定位应用开发
- IOS之地图和定位应用开发
- iOS开发地图应用,模拟器不询问我是否能获得定位权限
- IOS之地图和定位应用开发
- iOS开发之地图和定位应用开发
- IOS之地图和定位应用开发
- IOS之地图和定位应用开发
- IOS之地图和定位应用开发
- IOS之地图和定位应用开发
- 11.3 IOS之地图和定位应用开发