• iOS应用内跳转百度高德苹果地图


    移动开发经常用到基于位置的一些导航功能,但是对于对导航功能依赖性不强的的应用,我们直接采用应用外跳转地图APP即可。

    但是应用间跳转,首先需要设置白名单,

    在iOS 9 下涉及到平台客户端跳转,系统会自动到项目info.plist下检测是否设置平台Scheme,对于需要配置的平台,如果没有配置,将无法正常跳转平台客户端,因此需要配置Scheme名单。本文我们需要添加百度地图和高德地图的scheme白名单。

    具体方法:在项目的info.plist中添加LSApplicationQueriesSchemes字段,类型是Array,然后添加两个Item。

    下面直接上主要代码,网上高德都是直接导航的,为啥?都那么做?

    - (void)mapBtnclick{
       if (![NSString isNotEmptyString:_currentadress]) {
           [self.locationManager startUpdatingLocation];
           [SDIndicator showInfoWithMessage:@"正在定位,请稍候..."];
       }
       _actionSheet= [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:nil];
       NSMutableArray *mapsArray=[[NSMutableArray alloc] initWithCapacity:0];
       _mapsUrlArray=[[NSMutableArray alloc] init];
       NSURL * apple_App = [NSURL URLWithString:@"http://maps.apple.com/"];
       if ([[UIApplication sharedApplication] canOpenURL:apple_App]) {
           [mapsArray addObject:@"使用苹果自带地图导航"];
           NSString *urlString=[NSString stringWithFormat:@"http://maps.apple.com/?saddr=%f,%f&daddr=%f,%f",_strLatitude,_strLongitude,[_model.last_latitude floatValue],[_model.last_longitude floatValue] ];
           [_mapsUrlArray addObject:urlString];
       }
       
       NSURL * baidu_App = [NSURL URLWithString:@"baidumap://"];
       if ([[UIApplication sharedApplication] canOpenURL:baidu_App]) {
           [mapsArray addObject:@"使用百度地图导航"];
           
           NSString *stringURL =[[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%f,%f|name=%@&mode=driving&coord_type=gcj02",[_model.last_latitude floatValue],[_model.last_longitude floatValue],_model.address] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
           [_mapsUrlArray addObject:stringURL];
           
       }
       
       NSURL * gaode_App = [NSURL URLWithString:@"iosamap://"];
       if ([[UIApplication sharedApplication] canOpenURL:gaode_App]) {
           [mapsArray addObject:@"使用高德地图导航"];
           NSString *urlString = [[NSString stringWithFormat:@"iosamap://path?sourceApplication=%@&sid=BGVIS1&slat=%f&slon=%f&sname=%@&did=BGVIS2&dlat=%f&dlon=%f&dname=%@&dev=0&t=0",@"龙巅鱼邻",_strLatitude,_strLongitude,_currentadress,[_model.last_latitude floatValue],[_model.last_longitude floatValue],_model.address] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
           [_mapsUrlArray addObject:urlString];
           
       }
       
       for (int x=0; x<mapsArray.count; x++) {
           [_actionSheet addButtonWithTitle:[mapsArray objectAtIndex:x]];
           
       }
       
       if (_mapsUrlArray.count>0) {
            [_actionSheet showInView:self.view.window];
       }else{
           [SDIndicator showInfoWithMessage:@"建议您安装高德或者百度地图"];
       }
      
    }
    

     下面说一下,主要的知识点

    【1】

    使用canOpenURL方法来检测该手机是否安装相应APP

    该方法会返回一个BOOL值,当为YES时,表明已安装该APP

    【2】

    1、苹果自带地图(不需要检测,所以不需要URL Scheme)
    2、百度地图 baidumap://
    3、高德地图 iosamap://

    当然要携带参数的话,就按照各个地图的规则进行传值即可

    ByZqk

  • 相关阅读:
    c#中文字符串与byte数组互相转化
    c#的中英文混合字符串截取 public static string SubString(string inputString, int byteLength)
    c#的中英文混合字符串截取指定长度,startidx从0开始
    //字符是否为汉字
    //获得字节长度
    C# 截取中英文混合字符串分行显示宽度相同
    C#截取中英文混合字符串分行显示
    C#截取指定长度中英文字符串方法 (修改)
    截取字符串的长度(中英文)
    canvas贪吃蛇游戏
  • 原文地址:https://www.cnblogs.com/widgetbox/p/9025646.html
Copyright © 2020-2023  润新知