国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

ios開發中如何調用蘋果自帶地圖導航

2019-11-14 19:31:40
字體:
來源:轉載
供稿:網友

  前段時間一直在趕項目,在外包公司工作就是命苦,天天加班不說,工作都是和工期合同掛鉤的,稍微逾期就有可能被扣獎金,不談這些傷腦筋的事情了,讓我們說說iOS開發中如何調用蘋果手機自帶的地圖。

  學習如逆水行舟,不進則退。古人告訴我們要不斷的反思和總結,日思則日精,月思則月精,年思則年精。只有不斷的嘗試和總結,才能讓我們的工作和生活更加輕松愉快和美好。連著做了兩個大的商城外包項目,智慧城市,搜牧通,花費了近四個月的時間,終于在反復修改后完美收工。期間的困難自不必說,以后多多總結和溝通吧。百度地圖的使用之前已經發表了一篇文章,說的很詳細了,這里不再涉及,言歸正傳,我們說一下如何調用蘋果自帶的地圖

  第一步:導入地圖文件  #import <MapKit/MapKit.h>

  第二步:獲取當前位置和目的地的經緯度,然后打開地圖即可

  

  //獲取當前位置

    MKMapItem *mylocation = [MKMapItem mapItemForCurrentLocation];

    

    //當前經維度

    float currentLatitude=mylocation.placemark.location.coordinate.latitude;

    float currentLongitude=mylocation.placemark.location.coordinate.longitude;

    

    CLLocationCoordinate2D coords1 = CLLocationCoordinate2DMake(currentLatitude,currentLongitude);

    

    //目的地位置

    coordinate.latitude=[[dataSource objectForKey:@"lat"] floatValue];

    coordinate.longitude=[[dataSource objectForKey:@"lng"] floatValue];

    

    

    CLLocationCoordinate2D coords2 = coordinate;

    

    // ios6以下,調用google map

    if (SYSTEM_VERSION_LESS_THAN(@"6.0"))

    {

        NSString *urlString = [[NSString alloc] initWithFormat:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f&dirfl=d", coords1.latitude,coords1.longitude,coords2.latitude,coords2.longitude];

        NSURL *aURL = [NSURL URLWithString:urlString];

        //打開網頁google地圖

        [[UIapplication sharedApplication] openURL:aURL];

    }

    else

    // 直接調用ios自己帶的apple map

    {

        //當前的位置

        MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];

        //起點

        //MKMapItem *currentLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coords1 addressDictionary:nil]];

        //目的地的位置

        MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coords2 addressDictionary:nil]];

        

        toLocation.name = @"目的地";

        NSString *myname=[dataSource objectForKey:@"name"];

        if (![XtomFunction xfunc_check_strEmpty:myname])

        {

            toLocation.name =myname;

        }

        

        NSArray *items = [NSArray arrayWithObjects:currentLocation, toLocation, nil];

        NSDictionary *options = @{ MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving, MKLaunchOptionsMapTypeKey: [NSNumber numberWithInteger:MKMapTypeStandard], MKLaunchOptionsShowsTrafficKey:@YES };

        //打開蘋果自身地圖應用,并呈現特定的item

        [MKMapItem openMapsWithItems:items launchOptions:options];

    }

  

  通過這兩步就可以輕松的開啟蘋果自帶地圖導航,感覺真是挺不錯的,唯一的缺點是開啟地圖獲取路線信息耗費的手機流量比較大,最好在wifi條件下調用。如果不是必須,盡量還是用高德或者百度自帶的地圖就好。

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 无为县| 龙川县| 县级市| 都兰县| 区。| 阜新市| 利津县| 贵港市| 海伦市| 冕宁县| 枣庄市| 永嘉县| 资兴市| 清水县| 洛南县| 尼勒克县| 九江县| 博爱县| 开封市| 平潭县| 江北区| 玉山县| 北海市| 虎林市| 思茅市| 舒城县| 南充市| 平谷区| 辽源市| 新安县| 汉寿县| 孟州市| 湖北省| 灵石县| 永定县| 海阳市| 石河子市| 德格县| 陈巴尔虎旗| 巧家县| 永和县|