• IOS基礎學習之添加地圖定位方法

    0
    C/C++ Go iOS開發 IOS學習 ci 10926 次瀏覽
    IOS開發中,使用地圖只需要新建一個MKMapView,addSubView即可。如下:
    1、添加地圖
    1.1 新一個Single View app ,選擇默認項,創建后,在ViewController.h 
    1. #import <UIKit/UIKit.h>  
    2. #import <MapKit/MapKit.h>  
    3. #import <CoreLocation/CoreLocation.h>  
    4.   
    5. @interface ViewController : UIViewController   
    6. <MKMapViewDelegate, CLLocationManagerDelegate> {  
    7.     MKMapView *map;  
    8.     CLLocationManager *locationManager;  
    9. }  
    10. @end
    復制代碼

    1.2 在ViewController.m中添加
    1. - (void)viewDidLoad  
    2. {  
    3.     map = [[MKMapView alloc] initWithFrame:[self.view bounds]];  
    4.     map.showsUserLocation = YES;  
    5.     map.mapType = MKMapTypeSatellite;  
    6.     [self.view addSubview:map];  
    7.   
    8.   
    9.     [super viewDidLoad];  
    10.     // Do any additional setup after loading the view, typically from a nib.  
    11. }  
    復制代碼

    運行即可

    2、定位到指定經緯度

    1. CLLocationCoordinate2D coords = CLLocationCoordinate2DMake(39.915352,116.397105);  
    2.       
    3.     float zoomLevel = 0.02;  
    4.     MKCoordinateRegion region = MKCoordinateRegionMake(coords, MKCoordinateSpanMake(zoomLevel, zoomLevel));  
    5.     [map setRegion:[map regionThatFits:region] animated:YES];  
    6.          
    復制代碼

    點此查看更多IOS學習視頻教程。

    相似問題

    相關經驗

    相關資訊

    相關文檔

  • sesese色