您的位置:首页 > 移动开发 > IOS开发

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];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: