地图导航划线
来源:互联网 发布:天仕博软件 编辑:程序博客网 时间:2024/04/27 19:13
简单是ios地图划线事例 有上一篇关于地图的注释,着个应该很清楚了
//// ViewController.m// 2014_11_03_地图划线//// Created by Mac10.9 on 14-11-3.// Copyright (c) 2014年 xiaoxiaobing. All rights reserved.//#import "ViewController.h"#import <MapKit/MapKit.h>#import <CoreLocation/CoreLocation.h>#import "XXBAnnotation.h"@interface ViewController ()<MKMapViewDelegate,CLLocationManagerDelegate]] >//为了开启定位服务员@property (nonatomic, strong) CLLocationManager *locMgr;@property (weak, nonatomic) IBOutlet MKMapView *mapView;@property (nonatomic, strong) CLGeocoder *geocoder;@end@implementation ViewController- (void)viewDidLoad{ [super viewDidLoad]; [self setupCLLocationManager]; [self setupMapView];}/** * 懒加载 */- (CLLocationManager *)locMgr{#warning 定位服务不可用 if(![CLLocationManager locationServicesEnabled]) { /** 只有系统的定位功能是关闭的时候才会调用这个方法 */ return nil; } if (!_locMgr) { // 创建定位管理者 self.locMgr = [[CLLocationManager alloc] init]; // 设置代理 self.locMgr.delegate = self; } return _locMgr;}- (void)setupCLLocationManager{ // 开始定位用户的位置 [self.locMgr startUpdatingLocation]; [self.locMgr requestAlwaysAuthorization];}- (CLGeocoder *)geocoder{ if (!_geocoder) { self.geocoder = [[CLGeocoder alloc] init]; } return _geocoder;}- (void)setupMapView{ self.mapView.delegate = self; NSString *address1 = @"北京"; NSString *address2 = @"广州"; [self.geocoder geocodeAddressString:address1 completionHandler:^(NSArray *placemarks, NSError *error) { if (error) return; CLPlacemark *fromPm = [placemarks firstObject]; [self.geocoder geocodeAddressString:address2 completionHandler:^(NSArray *placemarks, NSError *error) { if (error) return; CLPlacemark *toPm = [placemarks firstObject]; [self addLineFrom:fromPm to:toPm]; }]; }];}/** * 添加导航的线路 * * @param fromPm 起始位置 * @param toPm 结束位置 */- (void)addLineFrom:(CLPlacemark *)fromPm to:(CLPlacemark *)toPm{ // 1.添加2个大头针 XXBAnnotation *fromAnno = [[XXBAnnotation alloc] init]; fromAnno.coordinate = fromPm.location.coordinate; fromAnno.title = fromPm.name; [self.mapView addAnnotation:fromAnno]; XXBAnnotation *toAnno = [[XXBAnnotation alloc] init]; toAnno.coordinate = toPm.location.coordinate; toAnno.title = toPm.name; [self.mapView addAnnotation:toAnno]; // 2.查找路线 // 方向请求 MKDirectionsRequest *request = [[MKDirectionsRequest alloc] init]; // 设置起点 MKPlacemark *sourcePm = [[MKPlacemark alloc] initWithPlacemark:fromPm]; request.source = [[MKMapItem alloc] initWithPlacemark:sourcePm]; // 设置终点 MKPlacemark *destinationPm = [[MKPlacemark alloc] initWithPlacemark:toPm]; request.destination = [[MKMapItem alloc] initWithPlacemark:destinationPm]; // 方向对象 MKDirections *directions = [[MKDirections alloc] initWithRequest:request]; // 计算路线 [directions calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response, NSError *error) { NSLog(@"总共%lu条路线", (unsigned long)response.routes.count); // 遍历所有的路线 for (MKRoute *route in response.routes) { // 添加路线遮盖 [self.mapView addOverlay:route.polyline]; } }];}#pragma mark - MKMapViewDelegate- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay{ MKPolylineRenderer *renderer = [[MKPolylineRenderer alloc] initWithOverlay:overlay]; renderer.strokeColor = [UIColor redColor]; return renderer;}@end
0 0
- 地图导航划线
- 地图与定位(四)导航划线
- iOS 地图源及目的地定位、划线和系统导航的使用
- iOS原生地图划线
- 微信小程序地图划线
- 在google地图上划线
- 在百度地图中自由的划线
- arcgis for android 地图上画框划线
- 地图占道划线(虚线)
- 划线功能更改(高德地图)
- arcgis for android 地图上画框划线
- 划线
- 51地图导航
- android地图导航
- 导航地图数据格式
- 室内外地图导航
- iOS 调用地图导航
- 微信高德导航地图
- Android Theme即样式 简介
- 指针
- Python os.path模块
- 27播放报警音乐
- linux 常用查找命令
- 地图导航划线
- C风格字符串
- 互联网创业网站推荐
- python staticmethod和classmethod
- ISO UITextView 做意见反馈
- Hibernate 关系映射 总结整理
- Python中调用父类的同名方法
- 在不知道第一响应者的情况下取消键盘方法
- Python类的专用方法:__init__ | __del__等