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) {
-
-
}
-
return self;
-
}
-
-
- (void)viewDidLoad
-
{
-
[super viewDidLoad];
-
-
-
MKMapView* mapview = [[MKMapView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
-
-
mapview.delegate = self;
-
-
mapview.showsUserLocation = YES;
-
-
-
-
-
-
-
-
mapview.mapType = MKMapTypeStandard;
-
-
-
CLLocationCoordinate2D coor2d = {33.00,112.52};
-
-
-
MKCoordinateSpan span = {5,5};
-
MKCoordinateRegion region = {coor2d,span};
-
-
-
-
-
[mapview setRegion:region];
-
[self.view addSubview:mapview];
-
locationmanager = [[CLLocationManager alloc]init];
-
-
-
-
-
-
-
-
-
-
-
-
[locationmanager setDesiredAccuracy:kCLLocationAccuracyBest];
-
-
locationmanager.delegate = self;
-
NSLog(@"开始定位");
-
-
[locationmanager startUpdatingLocation];
-
-
}
-
-
#pragma mark locationManager delegate
-
-
-
- (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);
-
-
-
-
-
-
-
geocoder = [[CLGeocoder alloc]init];
-
[geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray*placemarks,NSError* error)
-
{
-
-
for (CLPlacemark* place in placemarks) {
-
-
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");
-
}
-
-
}];
-
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
#pragma mark MKMapViewDelegate的代理方法
-
-
-
-
-
-
-
-
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
-
{
-
-
}
-
-
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
-
{
-
-
}
-
-
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
-
{
-
-
}
-
@end
iOS开发中地图(MapKit)的使用,布布扣,bubuko.com
iOS开发中地图(MapKit)的使用
原文:http://blog.csdn.net/eduora_meimei/article/details/23432555