你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS開發中地圖(MapKit)的使用

iOS開發中地圖(MapKit)的使用

編輯:IOS開發綜合

iOS開發中地圖(MapKit)的使用


首先要引入MapKit.framework的框架

將#import 的庫引進來


但是運行結果可以出現地圖但是一直出現這樣的錯誤該怎麼解決


Apr 7 18:26:27 Amorming.local dingwei[600] : CGBitmapContextCreate: unsupported parameter combination: 5 integer bits/component; 16 bits/pixel; 3-component color space; kCGImageAlphaNoneSkipLast; 512 bytes/row.

2014-04-07 18:26:27.843 dingwei[600:7b03] vImage decode failed, falling back to CG path.


以下是代碼

GPSViewController.h文件中

#import 
#import 
#import 
@interface GPSViewController : UIViewController

@property(nonatomic,retain) CLLocationManager* locationmanager;
@property(nonatomic,retain) CLGeocoder* geocoder;
@end

GPSViewController.m文件中

#import "GPSViewController.h"

@interface GPSViewController ()

@end

@implementation GPSViewController

@synthesize locationmanager,geocoder;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    //初始化地圖視圖
    MKMapView* mapview = [[MKMapView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
    //地圖的代理方法
    mapview.delegate = self;
    //是否顯示當前的位置
    mapview.showsUserLocation = YES;
    //地圖的類型, iOS開發中自帶的地圖
    //使用第三方的地圖可以查找周邊環境的餐館,學校之類的
    /*
     MKMapTypeStandard 標准地圖
     MKMapTypeSatellite 衛星地圖
     MKMapTypeHybrid 混合地圖
     */
    mapview.mapType = MKMapTypeStandard;
    
    //河南南陽的經緯度,初始化的坐標
    CLLocationCoordinate2D coor2d = {33.00,112.52};
    //CLLocationCoordinate2D coor2d = {37.7,112.4};
    //顯示范圍,數值越大,范圍就越大
    MKCoordinateSpan span = {5,5};
    MKCoordinateRegion region = {coor2d,span};
    //是否允許縮放,一般都會讓縮放的
    //mapview.zoomEnabled = NO;
    //mapview.scrollEnabled = NO;
    //地圖初始化時顯示的區域
    [mapview setRegion:region];
    [self.view addSubview:mapview];
    locationmanager = [[CLLocationManager alloc]init];
    
    //設置精度
    /*
     kCLLocationAccuracyBest
     kCLLocationAccuracyNearestTenMeters
     kCLLocationAccuracyHundredMeters
     kCLLocationAccuracyHundredMeters
     kCLLocationAccuracyKilometer
     kCLLocationAccuracyThreeKilometers
     */
    //設置定位的精度
    [locationmanager setDesiredAccuracy:kCLLocationAccuracyBest];
    //實現協議
    locationmanager.delegate = self;
    NSLog(@"開始定位");
    //開始定位
    [locationmanager startUpdatingLocation];
   
}

#pragma mark locationManager delegate

//實現定位 6.0 過期的做法
- (void)locationManager:(CLLocationManager *)manager
	didUpdateToLocation:(CLLocation *)newLocation
		   fromLocation:(CLLocation *)oldLocation
{
    NSLog(@"hello");
    //打印出精度和緯度
    CLLocationCoordinate2D coordinate = newLocation.coordinate;
    NSLog(@"輸出當前的精度和緯度");
    NSLog(@"精度:%f 緯度:%f",coordinate.latitude,coordinate.longitude);
    //停止定位
    [locationmanager stopUpdatingLocation];
    //計算兩個位置的距離
    float distance = [newLocation distanceFromLocation:oldLocation];
    NSLog(@" 距離 %f",distance);
    
    //====位置的反編碼 5.0 之後的
    /*
     
     */
    
   geocoder = [[CLGeocoder alloc]init];
    [geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray*placemarks,NSError* error)
     {
         //NSLog(@"hffjv");
         for (CLPlacemark* place in placemarks) {
             //NSLog(@"hffjv");
             NSLog(@"name %@",place.name); //位置
             NSLog(@"thoroughfare %@",place.thoroughfare);//街道
             //子街道
             NSLog(@"subthoroughfare %@",place.subAdministrativeArea);
             //市
             NSLog(@"loclitity %@",place.locality);
             //區
             NSLog(@"subLocality %@",place.subLocality);
             //國家
             NSLog(@"country %@",place.country);
             NSLog(@"hffjv");
         }
         
     }];
}

// 6.0 之後新增的位置調用方法

/*-(void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations
{
    for (CLLocation* location in locations) {
        NSLog(@"%@",location);
    }
    //停止定位
   // [manager stopUpdatingLocation];
    
}
*/
#pragma mark MKMapViewDelegate的代理方法
//返回標注視圖(大頭針視圖)
/*- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation
{
    
}*/

//更新當前位置調用
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    
}
//選中注釋圖標
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    
}
//地圖的顯示區域改變了調用
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
    
}
@end


  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved