iOS开发中地图(MapKit)的使用
iOS开发中地图(MapKit)的使用
首先要引入MapKit.framework的框架
将#import <MapKit/MapKit.h>的库引进来
但是运行结果可以出现地图但是一直出现这样的错误该怎么解决
Apr 7 18:26:27 Amorming.local dingwei[600] <Error>: 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 <UIKit/UIKit.h> #import <CoreLocation/CoreLocation.h> #import <MapKit/MapKit.h> @interface GPSViewController : UIViewController<CLLocationManagerDelegate,MKMapViewDelegate> @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 <MKAnnotation>)annotation { }*/ //更新当前位置调用 - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation { } //选中注释图标 - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view { } //地图的显示区域改变了调用 - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated { } @end
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。