zoukankan      html  css  js  c++  java
  • 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/C++插件开发框架(四)——核心层设计和实现
    构建自己的C/C++插件开发框架(二)——总体功能
    对企业来说,要放在第一位的是什么
    深入理解C++的动态绑定和静态绑定
    构建自己的C/C++插件开发框架(三)——总体结构
    管道和过滤器
    层模式——面向模式的体系结构学习笔记
    使用信元流(TLVStream)规范、简化模块(C/C++)间交互
    推荐博客
    Android 操作系统的内存回收机制
  • 原文地址:https://www.cnblogs.com/widgetbox/p/9025646.html
Copyright © 2011-2022 走看看