zoukankan      html  css  js  c++  java
  • iOS.定位服务与地图应用.06.调用iOS苹果地图

    #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
  • 相关阅读:
    addChildViewController ipad 中Controller的嵌套和叠加
    Oracle中sign函数和decode函数的使用
    MapReduce调度与执行原理之任务调度
    [置顶] SOLR 4.4 部署
    [笔试] 怪物安全问题
    优先队列的使用——Expedition
    棋盘分割——维数较大的动态规划
    由DAG到背包问题——记忆化搜索和递推两种解法
    硬币问题——记忆化搜索与递推的转换
    DAG上的动态规划---嵌套矩形(模板题)
  • 原文地址:https://www.cnblogs.com/cqchen/p/3802288.html
Copyright © 2011-2022 走看看