您的位置:首页 > 移动开发 > IOS开发

iOS开发中地图(MapKit)的使用

2014-04-07 18:31 507 查看
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];//设置精度/*kCLLocationAccuracyBestkCLLocationAccuracyNearestTenMeterskCLLocationAccuracyHundredMeterskCLLocationAccuracyHundredMeterskCLLocationAccuracyKilometerkCLLocationAccuracyThreeKilometers*///设置定位的精度[locationmanager setDesiredAccuracy:kCLLocationAccuracyBest];//实现协议locationmanager.delegate = self;NSLog(@"开始定位");//开始定位[locationmanager startUpdatingLocation];}#pragma mark locationManager delegate//实现定位 6.0 过期的做法- (void)locationManager:(CLLocationManager *)managerdidUpdateToLocation:(CLLocation *)newLocationfromLocation:(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 <MKAnnotation>)annotation{}*///更新当前位置调用- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{}//选中注释图标- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{}//地图的显示区域改变了调用- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{}@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: