iPhone开发之地图定位(CoreLocation和Mapkit框架)简易编程
2013-09-26 15:55
465 查看
下面介绍的时地图定位和位置反编码
//
// AppDelegate.h
// LocationDemo
//
#import
#import
#import
@interface AppDelegate : UIResponder<</span>UIApplicationDelegate,CLLocationManagerDelegate,MKReverseGeocoderDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
//
// AppDelegate.m
// LocationDemo
//
#import "AppDelegate.h"
@implementation AppDelegate
- (void)dealloc
{
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
//设置过滤信息
// [locationManager setDistanceFilter:<#(CLLocationDistance)#>]
//设置定位的精度
[locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
locationManager.delegate = self;
//开始实时定位
[locationManager startUpdatingLocation];
return YES;
}
//实时定位调用的方法, 6.0过期的方法
#pragma mark - CLLocationManager delegate
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
CLLocationCoordinate2D coordinate = newLocation.coordinate;
NSLog(@"经度:%f,纬度:%f",coordinate.longitude,coordinate.latitude);
//停止实时定位
[manager stopUpdatingLocation];
//计算两个位置的距离
// float distance = [newLocation distanceFromLocation:oldLocation];
// NSLog(@"%f",distance);
//------------------位置反编码---5.0之后使用-----------------
CLGeocoder *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.subThoroughfare); // 子街道
NSLog(@"locality,%@",place.locality); // 市
NSLog(@"subLocality,%@",place.subLocality); // 区
NSLog(@"country,%@",place.country); // 国家
}
}];
//----------------------位置反编码--5.0之前的使用-----------------
MKReverseGeocoder *mkgeocoder = [[MKReverseGeocoder alloc] initWithCoordinate:coordinate];
mkgeocoder.delegate = self;
[mkgeocoder start];
}
//6.0之后新增的位置调用方法
//- (void)locationManager:(CLLocationManager *)manager
// didUpdateLocations:(NSArray *)locations {
// for (CLLocation *location in locations) {
// NSLog(@"%@",location);
// }
//
// //停止实时定位
// [manager stopUpdatingLocation];
//
//}
#pragma mark - MKReverseGeocoder delegate
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder
didFindPlacemark:(MKPlacemark *)place {
NSLog(@"---name,%@",place.name); // 位置名
NSLog(@"---thoroughfare,%@",place.thoroughfare); // 街道
NSLog(@"---subThoroughfare,%@",place.subThoroughfare); // 子街道
NSLog(@"---locality,%@",place.locality); // 市
NSLog(@"---subLocality,%@",place.subLocality); // 区
NSLog(@"---country,%@",place.country); // 国家
}
@end
原文地址:http://blog.sina.com.cn/s/blog_aeb8e4450101avl5.html
//
// AppDelegate.h
// LocationDemo
//
#import
#import
#import
@interface AppDelegate : UIResponder<</span>UIApplicationDelegate,CLLocationManagerDelegate,MKReverseGeocoderDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
//
// AppDelegate.m
// LocationDemo
//
#import "AppDelegate.h"
@implementation AppDelegate
- (void)dealloc
{
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
//设置过滤信息
// [locationManager setDistanceFilter:<#(CLLocationDistance)#>]
//设置定位的精度
[locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
locationManager.delegate = self;
//开始实时定位
[locationManager startUpdatingLocation];
return YES;
}
//实时定位调用的方法, 6.0过期的方法
#pragma mark - CLLocationManager delegate
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
CLLocationCoordinate2D coordinate = newLocation.coordinate;
NSLog(@"经度:%f,纬度:%f",coordinate.longitude,coordinate.latitude);
//停止实时定位
[manager stopUpdatingLocation];
//计算两个位置的距离
// float distance = [newLocation distanceFromLocation:oldLocation];
// NSLog(@"%f",distance);
//------------------位置反编码---5.0之后使用-----------------
CLGeocoder *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.subThoroughfare); // 子街道
NSLog(@"locality,%@",place.locality); // 市
NSLog(@"subLocality,%@",place.subLocality); // 区
NSLog(@"country,%@",place.country); // 国家
}
}];
//----------------------位置反编码--5.0之前的使用-----------------
MKReverseGeocoder *mkgeocoder = [[MKReverseGeocoder alloc] initWithCoordinate:coordinate];
mkgeocoder.delegate = self;
[mkgeocoder start];
}
//6.0之后新增的位置调用方法
//- (void)locationManager:(CLLocationManager *)manager
// didUpdateLocations:(NSArray *)locations {
// for (CLLocation *location in locations) {
// NSLog(@"%@",location);
// }
//
// //停止实时定位
// [manager stopUpdatingLocation];
//
//}
#pragma mark - MKReverseGeocoder delegate
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder
didFindPlacemark:(MKPlacemark *)place {
NSLog(@"---name,%@",place.name); // 位置名
NSLog(@"---thoroughfare,%@",place.thoroughfare); // 街道
NSLog(@"---subThoroughfare,%@",place.subThoroughfare); // 子街道
NSLog(@"---locality,%@",place.locality); // 市
NSLog(@"---subLocality,%@",place.subLocality); // 区
NSLog(@"---country,%@",place.country); // 国家
}
@end
原文地址:http://blog.sina.com.cn/s/blog_aeb8e4450101avl5.html
相关文章推荐
- iOS开发之CoreLocation框架(地图/定位)
- iPhone开发之CoreLocation定位功能(6)
- iPhone的定位技术与Core Location框架
- CoreLocation框架地图定位(iOS9全适配)
- iOS定位开发之CoreLocation
- iOS学习笔记 地图(一)定位CoreLocation
- iOS 地图CoreLocation定位
- IOS 地图的开发(coreLocation)
- iOS开发 - CoreLocation地理定位
- iOS项目开发— CoreLocation的定位服务和地理编码与发编码实现
- [IOS地图开发系类]1、CLLocationManager 位置定位
- iPhone的定位技术与Core Location框架
- iPhone开发实战:定位与地图
- andro studio高德地图开发:显示定位蓝点
- [Android算法] android定位和地图开发实例
- iPhone开发进阶(5) --- 编程定制UIViewController
- iPhone实战:定位与地图
- [转载]iphone开发-地图注解(地图上的大头针
- 仿微信/QQ 开发基于XMPP的iPhone/iOS聊天客户端(三)CoreData
- 离岸iPhone 4编程开发 - 移动应用的未来