iOS在地图开发基础,有点乱,将就一下

来源:互联网 发布:Windows ftp 服务 编辑:程序博客网 时间:2024/05/01 10:10
定位和地图:定位:经纬度 获取现在位置的经纬度就是手机的定位zai info.plist 添加NSLocationAlwaysUsingsNSLocationAlwaysUsageDescriptionNSLocationAlwaysUsageDescriptionCLLocation *location=[locations firstObject];CLLocationCoordinate2D coordinate=location.coordinate; NSLog(@"%g %g",coordinate.latitude,coordinate.longitude);地理编码:--地名--获取经纬度地理反编码:经纬度--》地名@property (strong,nonatomic)CLGeocoder *gecoder;解码: [self.gecoder reverseGeocodeLocation:location completionHandler:^(NSArray * __nullable placemarks, NSError * __nullable error) { if (placemarks==nil || placemarks.count==0) { NSLog(@"can not find this place") ; } else { CLPlacemark *placemark=[placemarks firstObject]; NSLog(@"%@ %2f %2f %@ %@ %@",placemark.name,placemark.location.coordinate.latitude,placemark.location.coordinate.longitude,placemark.thoroughfare,placemark.subThoroughfare,placemark.subLocality); } }];编码: [self.gecoder geocodeAddressString:self.textPut.text completionHandler:^(NSArray * __nullable placemarks, NSError * __nullable error) { for (CLPlacemark *placeMark in placemarks) { NSLog(@"%.2f %.2f %@",placeMark.location.coordinate.latitude,placeMark.location.coordinate.longitude,placeMark.name); } }];定位:框架是:corelocation CLLocationManager 地理编码clgeocoder gecoder “,^—clplacemarkgeo geocodeAddressString:<#(nonnull NSString *)#> completionHandler:<#^(NSArray * __nullable placemarks, NSError * __nullable error)completionHandler#>CLLocation *location=[[CLLocation alloc] initWithLatitude:23 longitude:133];地图:mapkit.frameworkMKmapview自定义打头阵1.《MKannotation》location—2d title subtitle[self.map addannotation :SCHAnnotation]delegate;MKAnnotation —>MKPinAnnotationview(内容比较丰富)导航:mkmapitem MKMapItem openMapsWithItems:<#(nonnull NSArray *)#> launchOptions:<#(nullable NSDictionary *)#>地图上画线:MKdiretionsrequest source=placemark destinationmkdirection MKDirectionsRequest *mkRequest=[[MKDirectionsRequest alloc] init]; MKMapItem *sourceItem=[[MKMapItem alloc] initWithPlacemark:sourcePlace]; MKMapItem *destItem=[[MKMapItem alloc] initWithPlacemark:destPlaceMark]; mkRequest.destination=destItem; mkRequest.source=sourceItem; MKDirections *directions = [[MKDirections alloc]initWithRequest:mkRequest]; [directions calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse * __nullable response, NSError * __nullable error) { for (MKRoute *route in response.routes) { [self.map addOverlay:route.polyline]; } }];- (nonnull MKOverlayRenderer *)mapView:(nonnull MKMapView *)mapView rendererForOverlay:(nonnull id)overlay{ MKPolylineRenderer *line1=[[MKPolylineRenderer alloc]initWithOverlay:overlay]; line1.lineWidth=4; line1.strokeColor=[UIColor redColor]; // MKOverlayRenderer *lay=[[MKOverlayRenderer alloc] initWithOverlay:overlay]; return line1;}
0 0
原创粉丝点击