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 *)managerdidUpdateToLocation:(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 *)managerdidUpdateLocations:(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