iOS.定位服务与地图应用.06.调用iOS苹果地图
2014-06-22 10:52
645 查看
#import <UIKit/UIKit.h> #import <CoreLocation/CoreLocation.h> #import <MapKit/MapKit.h> @interface T20140621001526ViewController : UIViewController @property (weak, nonatomic) IBOutlet UITextField *txtQueryKey; @property (weak, nonatomic) IBOutlet UITextView *txtView; - (IBAction)geocodeQuery:(id)sender; @end
#import "T20140621001526ViewController.h" @interface T20140621001526ViewController () @end @implementation T20140621001526ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)geocodeQuery:(id)sender { if (_txtQueryKey.text == nil || [_txtQueryKey.text length] == 0) { return; } CLGeocoder *geocoder = [[CLGeocoder alloc] init]; [geocoder geocodeAddressString:_txtQueryKey.text completionHandler:^(NSArray *placemarks, NSError *error) { NSLog(@"查询记录数:%i",[placemarks count]); if ([placemarks count] > 0) { CLPlacemark* placemark = placemarks[0]; CLLocationCoordinate2D coordinate = placemark.location.coordinate; NSDictionary* address = placemark.addressDictionary; MKPlacemark *place = [[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:address]; MKMapItem *mapItem = [[MKMapItem alloc]initWithPlacemark:place]; [mapItem openInMapsWithLaunchOptions:nil]; /* //地图上设置行车路线 NSDictionary* options =[[NSDictionary alloc]initWithObjectsAndKeys: MKLaunchOptionsDirectionsModeDriving,MKLaunchOptionsDirectionsModeKey, nil]; MKMapItem *mapItem = [[MKMapItem alloc]initWithPlacemark:place]; [mapItem openInMapsWithLaunchOptions:options]; */ //关闭键盘 [_txtQueryKey resignFirstResponder]; } }]; } /* //多个点需要标注 - (IBAction)geocodeQuery:(id)sender { if (_txtQueryKey.text == nil || [_txtQueryKey.text length] == 0) { return; } CLGeocoder *geocoder = [[CLGeocoder alloc] init]; [geocoder geocodeAddressString:_txtQueryKey.text completionHandler:^(NSArray *placemarks, NSError *error) { NSLog(@"查询记录数:%i",[placemarks count]); NSMutableArray* array = [NSMutableArray new]; for (int i = 0; i < [placemarks count]; i++) { CLPlacemark* placemark = placemarks[i]; CLLocationCoordinate2D coordinate = placemark.location.coordinate; NSDictionary* address = placemark.addressDictionary; MKPlacemark *place = [[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:address]; MKMapItem *mapItem = [[MKMapItem alloc]initWithPlacemark:place]; [array addObject:mapItem]; } //关闭键盘 [_txtQueryKey resignFirstResponder]; if ([array count] > 0) { [MKMapItem openMapsWithItems:array launchOptions:nil]; } }]; } */ @end
相关文章推荐
- iOS定位服务与地图开发(5)---使用程序外地图之调用iOS 6苹果地图
- iOS.定位服务与地图应用.04.使用iOS苹果地图
- iOS.定位服务与地图应用.07.调用谷歌Web地图
- iOS定位服务与地图开发(6)---使用程序外地图之调用谷歌Web地图
- iOS.定位服务与地图应用.03.地理信息编码查询
- iOS.定位服务与地图应用.02.地理信息反编码
- iOS开发调用苹果自带的地图应用
- iOS.定位服务与地图应用.01.定位服务编程
- iOS开发调用苹果自带的地图应用
- 类似美团的iOS地图定位及调用苹果系统导航
- iOS.定位服务与地图应用.05.跟踪用户位置变化
- 判断一个坐标点是否在一个无规则的多边形内 (iOS定位服务与地图应用开发:高德地图开发)
- iOS程序中调用系统自带应用(短信,邮件,浏览器,地图,appstore,拨打电话)
- iOS 6苹果地图应用(MapKit)-打开外部应用
- ios 里如何判断当前应用的定位服务是否可用
- iOS 6苹果地图应用(MapKit)-内置开发
- iOS程序中调用系统自带应用(短信,邮件,浏览器,地图,appstore,拨打电话)
- 转 iOS程序中调用系统自带应用(短信,邮件,浏览器,地图,appstore,拨打电话)
- IOS之地图和定位应用开发
- 转 ios 里如何判断当前应用的定位服务是否可用