MapView的应用
2015-09-24 08:35
435 查看
MapView在8.0之后,用法有了一些新的用法(代理方法),在此之前需要导入#import <MapKit/MapKit.h>
//创建位置服务对象 locationManager = [[CLLocationManager alloc] init]; locationManager.desiredAccuracy = kCLLocationAccuracyBest; //设置定位代理 locationManager.delegate = self; //如果实在iOS8.0之后,我们需要添加以下操作 //1.调用方法--requestWhenInUseAuthorization 或者 requestAlwaysAuthorization //2. if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) { [locationManager requestWhenInUseAuthorization]; } //开始定位 [locationManager startUpdatingLocation]; }
- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}
#pragma mark -CLLocationManagerDelegate- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{ NSLog(@"定位成功"); //停止定位 [locationManager stopUpdatingLocation]; CLLocationCoordinate2D coordinate = newLocation.coordinate; NSLog(@"位置:纬度:%.2f----经度:%.2f", coordinate.latitude, coordinate.longitude); }
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ NSLog(@"新方法定位成功"); //停止定位 [locationManager stopUpdatingLocation]; CLLocation *location = [locations lastObject]; CLLocationCoordinate2D coordinate = location.coordinate;
NSLog(@"位置:纬度:%.2f----经度:%.2f", coordinate.latitude, coordinate.longitude); //在iOS5.0之前使用位置反编码 MKReverseGeocoder *mkReverse = [[MKReverseGeocoder alloc] initWithCoordinate:coordinate]; mkReverse.delegate = self; //开始反编码 [mkReverse start]; CLGeocoder *geocoder = [[CLGeocoder alloc] init]; [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) { NSLog(@"---------CLGeocoder---------------"); for (CLPlacemark *place in placemarks) { NSLog(@"name,%@",place.name); // 位置名 NSLog(@"thoroughfare,%@",place.thoroughfare); // 街道 NSLog(@"subThoroughfare,%@",place.subThoroughfare); // 子街道 NSLog(@"locality,%@",place.locality); // 市 NSLog(@"subLocality,%@",place.subLocality); // 区 NSLog(@"country,%@",place.country); // 国家 } } ]; // CLGeocoder反编码 }
#pragma mark -MKReverseGeocoderDelegate- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)place{ NSLog(@"-----------MKReverseGeocoderDelegate----------"); NSLog(@"name,%@",place.name); // 位置名 NSLog(@"thoroughfare,%@",place.thoroughfare); // 街道 NSLog(@"subThoroughfare,%@",place.subThoroughfare); // 子街道 NSLog(@"locality,%@",place.locality); // 市 NSLog(@"subLocality,%@",place.subLocality); // 区 NSLog(@"country,%@",place.country); // 国家}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{ NSLog(@"error is %@", error);}
//创建位置服务对象 locationManager = [[CLLocationManager alloc] init]; locationManager.desiredAccuracy = kCLLocationAccuracyBest; //设置定位代理 locationManager.delegate = self; //如果实在iOS8.0之后,我们需要添加以下操作 //1.调用方法--requestWhenInUseAuthorization 或者 requestAlwaysAuthorization //2. if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) { [locationManager requestWhenInUseAuthorization]; } //开始定位 [locationManager startUpdatingLocation]; }
- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}
#pragma mark -CLLocationManagerDelegate- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{ NSLog(@"定位成功"); //停止定位 [locationManager stopUpdatingLocation]; CLLocationCoordinate2D coordinate = newLocation.coordinate; NSLog(@"位置:纬度:%.2f----经度:%.2f", coordinate.latitude, coordinate.longitude); }
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ NSLog(@"新方法定位成功"); //停止定位 [locationManager stopUpdatingLocation]; CLLocation *location = [locations lastObject]; CLLocationCoordinate2D coordinate = location.coordinate;
NSLog(@"位置:纬度:%.2f----经度:%.2f", coordinate.latitude, coordinate.longitude); //在iOS5.0之前使用位置反编码 MKReverseGeocoder *mkReverse = [[MKReverseGeocoder alloc] initWithCoordinate:coordinate]; mkReverse.delegate = self; //开始反编码 [mkReverse start]; CLGeocoder *geocoder = [[CLGeocoder alloc] init]; [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) { NSLog(@"---------CLGeocoder---------------"); for (CLPlacemark *place in placemarks) { NSLog(@"name,%@",place.name); // 位置名 NSLog(@"thoroughfare,%@",place.thoroughfare); // 街道 NSLog(@"subThoroughfare,%@",place.subThoroughfare); // 子街道 NSLog(@"locality,%@",place.locality); // 市 NSLog(@"subLocality,%@",place.subLocality); // 区 NSLog(@"country,%@",place.country); // 国家 } } ]; // CLGeocoder反编码 }
#pragma mark -MKReverseGeocoderDelegate- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)place{ NSLog(@"-----------MKReverseGeocoderDelegate----------"); NSLog(@"name,%@",place.name); // 位置名 NSLog(@"thoroughfare,%@",place.thoroughfare); // 街道 NSLog(@"subThoroughfare,%@",place.subThoroughfare); // 子街道 NSLog(@"locality,%@",place.locality); // 市 NSLog(@"subLocality,%@",place.subLocality); // 区 NSLog(@"country,%@",place.country); // 国家}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{ NSLog(@"error is %@", error);}
相关文章推荐
- 百度地图经纬度转换到腾讯地图/Google 对应的经纬度
- 在Google 地图上实现做的标记相连接
- PHP计算百度地图两个GPS坐标之间距离的方法
- sogou地图API用法实例教程
- gps各种地图坐标系转换
- [IOS地图开发系类]1、CLLocationManager 位置定位
- [IOS地图开发系类]2、位置解码CLGeocoder
- [IOS地图开发系类]3、地图视图MKMapview
- [IOS地图开发系类]4、MKMapview上添加MKAnnotationView,标记当前位置
- [IOS地图开发系类]5、改变大头针MKPinAnnotationView的颜色
- 魔兽地图修改器
- 国家测绘局副局长解释什么是“问题地图”ぁ
- 地图 点聚合
- asp.net地理统计图表控件
- Yahoo前端优化性能规则
- android google map研究
- ADS-B雷达显示终端 5.6
- ios 地图大头针自定义显示图片 MKAnnotationView
- 根据经纬度获得城市
- 3D地图