zoukankan      html  css  js  c++  java
  • iOS.定位服务与地图应用.03.地理信息编码查询

    #import <UIKit/UIKit.h>
    #import <CoreLocation/CoreLocation.h>
    #import <AddressBook/AddressBook.h>
    #import <AddressBookUI/AddressBookUI.h>
    
    @interface T20140621221104ViewController : UIViewController
    
    @property (weak, nonatomic) IBOutlet UITextField *txtQueryKey;
    
    @property (weak, nonatomic) IBOutlet UITextView *txtView;
    
    - (IBAction)geocodeQuery:(id)sender;
    
    @end
    #import "T20140621221104ViewController.h"
    
    @interface T20140621221104ViewController ()
    
    @end
    
    @implementation T20140621221104ViewController
    
    - (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;
                NSString* strCoordinate  = [NSString stringWithFormat:@"经度:%3.5f 
    纬度:%3.5f",coordinate.latitude, coordinate.longitude];
                
                NSDictionary *addressDictionary =  placemark.addressDictionary;
                
                NSString *address = [addressDictionary
                                     objectForKey:(NSString *)kABPersonAddressStreetKey];
                address = address == nil ? @"": address;
                
                NSString *state = [addressDictionary
                                   objectForKey:(NSString *)kABPersonAddressStateKey];
                state = state == nil ? @"": state;
                
                NSString *city = [addressDictionary
                                  objectForKey:(NSString *)kABPersonAddressCityKey];
                city = city == nil ? @"": city;
                
                _txtView.text = [NSString stringWithFormat:@"%@ 
     %@ 
    %@ 
    %@",strCoordinate,state, address,city];
                
                //关闭键盘
                [_txtQueryKey resignFirstResponder];
            }
        }];
        
    }
    
    @end
  • 相关阅读:
    IE浏览器中Image对象onload失效的解决办法
    jquery.lazyload 实现图片延迟加载jquery插件
    在JS方法中返回多个值的三种方法
    遭遇input与button按钮背景图失效不显示的解决办法
    jquery:validate的例子
    JavaScript toLowerCase() 方法 把字符串转换为小写
    Linux下的MySQL简单操作(服务启动与关闭、启动与关闭、查看版本)
    phpcms-v9视频模型的添加
    Linux下如何查看tomcat是否启动
    margin-top无效的问题解决方法
  • 原文地址:https://www.cnblogs.com/cqchen/p/3802081.html
Copyright © 2011-2022 走看看