zoukankan      html  css  js  c++  java
  • 绘制系统地图路线

    #import "ViewController.h"
    #import <MapKit/MapKit.h>
    #import <CoreLocation/CoreLocation.h>
    
    @interface ViewController ()
    
    
    /** 地理编码 */
    @property (nonatomic, strong) CLGeocoder *geoC;
    
    
    @end
    
    @implementation ViewController
    
    
    #pragma mark -懒加载
    -(CLGeocoder *)geoC
    {
        if (!_geoC) {
            _geoC = [[CLGeocoder alloc] init];
        }
        return _geoC;
    }
    
    
    
    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    {
       [self.geoC geocodeAddressString:@"广州" completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
           // 广州地标
           CLPlacemark *gzPL = [placemarks firstObject];
           [self.geoC geocodeAddressString:@"上海" completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
               // 上海地标
               CLPlacemark *shPL = [placemarks firstObject];
               
               [self systemNavWithBeginPL:gzPL endPL:shPL];
               
               
           }];
           
           
       }];
        
    
        
      
        
     
    }
    
    
    /**
     *  根据起点和终点地标对象,调用系统APP进行导航
     *
     *  @param beginCLPL 起点地标
     *  @param endCLPL   终点地标
     */
    -(void)systemNavWithBeginPL:(CLPlacemark *)beginCLPL endPL : (CLPlacemark *)endCLPL
    {
        // 调用系统的APP进行导航
    
        // 地图起点地标对象
        MKPlacemark *beginPL = [[MKPlacemark alloc] initWithPlacemark:beginCLPL];
        // 起点
        MKMapItem *beginItem = [[MKMapItem alloc] initWithPlacemark:beginPL];
        
    
        // 地图终点地标对象
        MKPlacemark *endPL = [[MKPlacemark alloc] initWithPlacemark:endCLPL];
        // 终点
        MKMapItem *endItem = [[MKMapItem alloc] initWithPlacemark:endPL];
        
        
        // 起点和终点数组
        NSArray *items = @[beginItem, endItem];
        
        // 设置地图启动项(导航模式:驾驶, 地图类型: 混合, 是否显示交通: 是)
        NSDictionary *dic = @{
                              MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving,
                              MKLaunchOptionsMapTypeKey : @(MKMapTypeHybrid),
                              MKLaunchOptionsShowsTrafficKey : @(YES),
                              
                              };
        
        // 给定两个点,起点和终点, 然后设置启动项, 开始调用系统APP进行导航
        [MKMapItem openMapsWithItems:items launchOptions:dic];
    }
    
    
    @end
    

      

  • 相关阅读:
    wpf-x-指令元素
    意法半导体STM32单片机特性
    非易失性存储器MRAM的两大优点
    静态SDRAM和动态SDRAM的区别
    使用SRAM如何节省芯片面积
    不同类别存储器基本原理
    串口SRAM和并口SRAM的引脚区别
    SRAM存储器芯片地址引脚线短路检测方法
    2020年国内MCU市场有望突破500亿元
    MRAM可以替代NOR或SRAM
  • 原文地址:https://www.cnblogs.com/yedayi/p/5143967.html
Copyright © 2011-2022 走看看