iOS 跳轉(zhuǎn)地圖(谷歌,高德,百度,騰訊,蘋果)

功能包括跳轉(zhuǎn)谷歌地圖,高德地圖,百度地圖,騰訊地圖,蘋果地圖
其中

百度地圖官方文檔慨绳。
高德地圖官方文檔
蘋果地圖官方文檔
谷歌地圖官方文檔
騰訊地圖官方文檔

  • 白名單設置,放到info.plist
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>googlechromes</string>
        <string>comgooglemaps</string>
        <string>baidumap</string>
        <string>qqmap</string>
        <string>iosamap</string>
        <string>alipay</string>
        <string>alipayshare</string>
        <string>wechat</string>
        <string>weixin</string>
        <string>sinaweibohd</string>
        <string>sinaweibo</string>
        <string>sinaweibosso</string>
        <string>weibosdk</string>
        <string>weibosdk2.5</string>
        <string>mqqapi</string>
        <string>mqq</string>
        <string>mqqOpensdkSSoLogin</string>
        <string>mqqconnect</string>
        <string>mqqopensdkdataline</string>
        <string>mqqopensdkgrouptribeshare</string>
        <string>mqqopensdkfriend</string>
        <string>mqqopensdkapi</string>
        <string>mqqopensdkapiV2</string>
        <string>mqqopensdkapiV3</string>
        <string>mqzoneopensdk</string>
        <string>wtloginmqq</string>
        <string>wtloginmqq2</string>
        <string>mqqwpa</string>
        <string>mqzone</string>
        <string>mqzonev2</string>
        <string>mqzoneshare</string>
        <string>wtloginqzone</string>
        <string>mqzonewx</string>
        <string>mqzoneopensdkapiV2</string>
        <string>mqzoneopensdkapi19</string>
        <string>mqzoneopensdkapi</string>
        <string>mqzoneopensdk</string>
        <string>renrenios</string>
        <string>renrenapi</string>
        <string>renren</string>
        <string>renreniphone</string>
        <string>yixin</string>
        <string>instagram</string>
        <string>whatsapp</string>
        <string>line</string>
        <string>fbapi</string>
        <string>fb-messenger-api</string>
        <string>fbauth2</string>
        <string>fbshareextension</string>
        <string>fbauth</string>
    </array>
+ (NSString *)appName
{
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    return [infoDictionary objectForKey:@"CFBundleName"];
}
/**
 打開地圖

 @param latitude 緯度
 @param longitude 經(jīng)度
 @param targetName 目的地名稱
 */
+ (void)openMapWithLatitude:(CGFloat)latitude longitude:(CGFloat)longitude targetName:(NSString *)targetName;
+ (void)openMapWithLatitude:(CGFloat)latitude longitude:(CGFloat)longitude targetName:(NSString *)targetName
{
    MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
    //緯度
    float currentLatitude = currentLocation.placemark.location.coordinate.latitude;
    //經(jīng)度
    float currentLongitude = currentLocation.placemark.location.coordinate.longitude;
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil
                                                                      preferredStyle:UIAlertControllerStyleActionSheet];
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://map/"]]) {
        [alertController addAction:[UIAlertAction actionWithTitle:@"谷歌地圖"style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSString *urlString = [[NSString stringWithFormat:@"comgooglemaps://?x-source=%@&x-success=%@&saddr=&daddr=%f,%f&directionsmode=driving",
                                    [FTPhoneInfo appName],
                                    AppUrlSchema,
                                    latitude,
                                    longitude]
                                   stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
        }]];
    }
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://map/"]]) {
        UIAlertAction *baiduMapAction = [UIAlertAction actionWithTitle:@"百度地圖" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSString *baiduParameterFormat = @"baidumap://map/direction?origin=latlng:%f,%f|name:我的位置&destination=latlng:%f,%f|name:%@&mode=driving";
            NSString *urlString = [[NSString stringWithFormat:
                                    baiduParameterFormat,currentLatitude,currentLongitude,latitude,longitude,targetName]
                                   stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
        }];
        [alertController addAction:baiduMapAction];
    }
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://map/"]]) {
        UIAlertAction *gaodeMapAction = [UIAlertAction actionWithTitle:@"高德地圖" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSString *gaodeParameterFormat = @"iosamap://navi?sourceApplication=%@&backScheme=%@&poiname=%@&lat=%f&lon=%f&dev=1&style=2";
            NSString *urlString = [[NSString stringWithFormat:
                                    gaodeParameterFormat,
                                    [FTPhoneInfo appName],
                                    AppUrlSchema,
                                    targetName,
                                    latitude,
                                    longitude]
                                   stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
        }];
        [alertController addAction:gaodeMapAction];
    }
    
    [alertController addAction:[UIAlertAction actionWithTitle:@"蘋果地圖" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        //起點
        MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
        CLLocationCoordinate2D desCorrdinate = CLLocationCoordinate2DMake(latitude,longitude);
        //終點
        MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:desCorrdinate addressDictionary:nil]];
        toLocation.name = targetName;
        //默認駕車
        [MKMapItem openMapsWithItems:@[currentLocation, toLocation]
                       launchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving,
                                       MKLaunchOptionsMapTypeKey:[NSNumber numberWithInteger:MKMapTypeStandard],
                                       MKLaunchOptionsShowsTrafficKey:[NSNumber numberWithBool:YES]}];
    }]];
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"qqmap://map/"]]) {
        [alertController addAction:[UIAlertAction actionWithTitle:@"騰訊地圖" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSString *QQParameterFormat = @"qqmap://map/routeplan?type=drive&fromcoord=%f, %f&tocoord=%f,%f&coord_type=1&policy=0&refer=%@";
            NSString *urlString = [[NSString stringWithFormat:
                                    QQParameterFormat,
                                    currentLatitude,
                                    currentLongitude,
                                    latitude,
                                    longitude,
                                    [FTPhoneInfo appName]]
                                   stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
        }]];
    }
    
    UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel                                                             handler:^(UIAlertAction * action) {}];
    [alertController addAction:cancelAction];
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市糠溜,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 223,002評論 6 519
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件樟凄,死亡現(xiàn)場離奇詭異,居然都是意外死亡兄渺,警方通過查閱死者的電腦和手機缝龄,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,357評論 3 400
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來溶耘,“玉大人二拐,你說我怎么就攤上這事〉时” “怎么了百新?”我有些...
    開封第一講書人閱讀 169,787評論 0 365
  • 文/不壞的土叔 我叫張陵,是天一觀的道長庐扫。 經(jīng)常有香客問我饭望,道長,這世上最難降的妖魔是什么形庭? 我笑而不...
    開封第一講書人閱讀 60,237評論 1 300
  • 正文 為了忘掉前任铅辞,我火速辦了婚禮,結(jié)果婚禮上萨醒,老公的妹妹穿的比我還像新娘斟珊。我一直安慰自己,他們只是感情好富纸,可當我...
    茶點故事閱讀 69,237評論 6 398
  • 文/花漫 我一把揭開白布囤踩。 她就那樣靜靜地躺著,像睡著了一般晓褪。 火紅的嫁衣襯著肌膚如雪堵漱。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,821評論 1 314
  • 那天涣仿,我揣著相機與錄音勤庐,去河邊找鬼。 笑死好港,一個胖子當著我的面吹牛愉镰,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播钧汹,決...
    沈念sama閱讀 41,236評論 3 424
  • 文/蒼蘭香墨 我猛地睜開眼岛杀,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了崭孤?” 一聲冷哼從身側(cè)響起类嗤,我...
    開封第一講書人閱讀 40,196評論 0 277
  • 序言:老撾萬榮一對情侶失蹤糊肠,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后遗锣,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體货裹,經(jīng)...
    沈念sama閱讀 46,716評論 1 320
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,794評論 3 343
  • 正文 我和宋清朗相戀三年精偿,在試婚紗的時候發(fā)現(xiàn)自己被綠了弧圆。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,928評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡笔咽,死狀恐怖搔预,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情叶组,我是刑警寧澤拯田,帶...
    沈念sama閱讀 36,583評論 5 351
  • 正文 年R本政府宣布,位于F島的核電站甩十,受9級特大地震影響船庇,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜侣监,卻給世界環(huán)境...
    茶點故事閱讀 42,264評論 3 336
  • 文/蒙蒙 一鸭轮、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧橄霉,春花似錦窃爷、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,755評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至覆糟,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間遮咖,已是汗流浹背滩字。 一陣腳步聲響...
    開封第一講書人閱讀 33,869評論 1 274
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留御吞,地道東北人麦箍。 一個月前我還...
    沈念sama閱讀 49,378評論 3 379
  • 正文 我出身青樓,卻偏偏與公主長得像陶珠,于是被迫代替她去往敵國和親挟裂。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 45,937評論 2 361