iOS 地图制作讲义

来源:互联网 发布:广东省发票打印软件 编辑:程序博客网 时间:2024/06/07 07:09

.系统原生地图 

1.什么是LBS

LBS:基于位置的服务   Location Based Service

实际应用:大众点评,陌陌,微信,百度地图

2.定位原理

1.GPS定位        2.基站定位    3.WIFI定位

3.定位使用框架

MapKit:显示地图

CoreLocation:定位框架,没有地图时也可以定位.

4.如何使用系统地图

1).初始化MapView

_mapView = [[MKMapViewalloc]initWithFrame:self.view.bounds];

   [self.viewaddSubview:_mapView];

2).设置地图中心坐标点

CLLocationCoordinate2D cl2d =CLLocationCoordinate2DMake(22.540396,113.951832);

   _mapView.centerCoordinate = cl2d;


3)设置地图显示区域

MKCoordinateSpan span =MKCoordinateSpanMake(0.01,0.01);

   MKCoordinateRegion region =MKCoordinateRegionMake(cl2d, span);

   _mapView.region = region;

4).设置地地图类型

_mapView.mapType =MKMapTypeStandard;


5).允许显示自己的位置

_mapView.showsUserLocation =YES;


6).初始化定位管理器

_manager = [[CLLocationManageralloc]init];

_manager.delegate =self;


7).ios8如何定位

1.在info.plist中添加  Privacy - Location Usage Description  ,  NSLocationAlwaysUsageDescription

2.在代码中  [_manager requestAlwaysAuthorization];

8).定位成功代理

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations


9).定位失败代理

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error


10).自定义大头针

    - (CLLocationCoordinate2D)coordinate;

- (NSString *)title;

- (NSString *)subtitle;

- (id)initWithCoordinate:(CLLocationCoordinate2D )cl2d andTitle:(NSString *)title andSubTitle:(NSString *)subTitle;


- (id)initWithCoordinate:(CLLocationCoordinate2D)cl2d andTitle:(NSString *)title andSubTitle:(NSString *)subTitle

{

   if (self = [superinit]) {

       _cl2d = cl2d;

       _title = title;

       _subTitle = subTitle;

   }

  returnself;

}

11).大头针的复用及定制

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation

{

   staticNSString *reused =@"reused";

   MKPinAnnotationView *pin = (MKPinAnnotationView *)[mapViewdequeueReusableAnnotationViewWithIdentifier:reused];

   if (pin ==nil) {

       pin = [[MKPinAnnotationViewalloc]initWithAnnotation:annotationreuseIdentifier:reused];

       pin.canShowCallout =YES;

       pin.pinColor =MKPinAnnotationColorGreen;

       pin.animatesDrop =YES;

        

       UIView *v = [[UIViewalloc]initWithFrame:CGRectMake(0,0,35, 35)];

        v.backgroundColor = [UIColorredColor];

        pin.leftCalloutAccessoryView = v;

        

       UIButton *b = [UIButtonbuttonWithType:UIButtonTypeSystem];

       b.frame =CGRectMake(0,0,35, 35);

        [b setTitle:@"按钮"forState:UIControlStateNormal];

       pin.rightCalloutAccessoryView = b;

   }

   return pin;

}

12).屏幕坐标转经纬度坐标

CLLocationCoordinate2D cl2d = [_mapViewconvertPoint:pointtoCoordinateFromView:_mapView];


13).反地理编码

CLLocation *location = [[CLLocationalloc]initWithLatitude:cl2d.latitudelongitude:cl2d.longitude];

       CLGeocoder *geocoder = [[CLGeocoderalloc]init];

       [geocoder reverseGeocodeLocation:locationcompletionHandler:^(NSArray *placemarks,NSError *error) {

           CLPlacemark *mark = [placemarks lastObject];

           myPin *pin = [[myPinalloc]initWithCoordinate:cl2dandTitle:mark.countryandSubTitle:mark.name];

           [_mapViewaddAnnotation:pin];

       }];

14).移除大头针

[_mapViewremoveAnnotations:_mapView.annotations];

二.高德地图的使用


 http://lbs.amap.com

  根据文档实现


1:地图的显示

     2:POI 搜索


0 0
原创粉丝点击