調(diào)用蘋果本地地圖跳轉(zhuǎn)

開始也是 導(dǎo)入MapKit.framework
IOS8要請(qǐng)求定位
獲取本地位置有兩種方法 1 MKMapItem *mylocation = [MKMapItem mapItemForCurrentLocation];
2 代理方法調(diào)用返回 userLocation(內(nèi)有經(jīng)緯度) 它有經(jīng)緯度再轉(zhuǎn):
CLLocationCoordinate2D coords1 = CLLocationCoordinate2DMake(23.127923,113.388557);
MKMapItem *currentLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coords1 addressDictionary:nil]];

import "ViewController.h"

        #import <MapKit/MapKit.h>

        @interface ViewController ()<MKMapViewDelegate>{
            NSArray *_items;

        }

        @property (weak, nonatomic) IBOutlet MKMapView *mapView;

        @end

        @implementation ViewController

        - (void)viewDidLoad {
            [super viewDidLoad];
            
            // 地圖類型
            //    MKMapTypeStandard = 0, 默認(rèn) 標(biāo)準(zhǔn)
            //    MKMapTypeSatellite, 衛(wèi)星
            //    MKMapTypeHybrid 混合 = 標(biāo)準(zhǔn) + 衛(wèi)星
            self.mapView.mapType = MKMapTypeStandard;
            
            // 用戶位置跟蹤模式
            //    MKUserTrackingModeNone = 0, //用戶位置,不請(qǐng)?jiān)试S跟蹤
            //    MKUserTrackingModeFollow, // 用戶位置允許跟蹤
            //    MKUserTrackingModeFollowWithHeading,用戶位置允許跟蹤(方向)
            self.mapView.userTrackingMode = MKUserTrackingModeFollow;
            
            // 設(shè)置mapView代理
            self.mapView.delegate = self;
            
            
            MKMapItem *mylocation = [MKMapItem mapItemForCurrentLocation];
             CLLocationCoordinate2D coords1 = CLLocationCoordinate2DMake(23.127923,113.388557);
            
            
             CLLocationCoordinate2D coords2 = CLLocationCoordinate2DMake(23.05,113.15);
            
             MKMapItem *currentLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coords1 addressDictionary:nil]];
            
             MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coords2 addressDictionary:nil]];
             _items = [NSArray arrayWithObjects:mylocation, toLocation, nil];
            
            NSDictionary *options = @{ MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving, MKLaunchOptionsMapTypeKey: [NSNumber numberWithInteger:MKMapTypeStandard], MKLaunchOptionsShowsTrafficKey:@YES };
            
            // [MKMapItem openMapsWithItems:items launchOptions:options];
            
        }

        -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
            NSDictionary *options = @{ MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving, MKLaunchOptionsMapTypeKey: [NSNumber numberWithInteger:MKMapTypeStandard], MKLaunchOptionsShowsTrafficKey:@YES };

            [MKMapItem openMapsWithItems:_items launchOptions:options];
        }



        -(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{
            // 1.當(dāng)前位置詳細(xì)描述
            userLocation.title = @"廣州";
            userLocation.subtitle = @"天河";

            //當(dāng)前的位置詳細(xì)描述,要顯示哪個(gè)城市,哪個(gè)區(qū)-(反地理編碼)
            //當(dāng)前位置信息
            NSLog(@"%f----%f",userLocation.coordinate.latitude,userLocation.coordinate.longitude);
            
            // 2.設(shè)置顯示的region
            //MKCoordinateSpan span = MKCoordinateSpanMake(0.193626, 0.145513);
            MKCoordinateSpan span = MKCoordinateSpanMake(0.085125, 0.015596);
            MKCoordinateRegion region = MKCoordinateRegionMake(self.mapView.userLocation.coordinate, span);
            self.mapView.region = region;
        #pragma mark 在此方法, 動(dòng)畫效果不起作用,其它方法方法可以
            //[self.mapView setRegion:region animated:YES];

        }
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容