zoukankan      html  css  js  c++  java
  • iOS.定位服务与地图应用.07.调用谷歌Web地图

    #import <UIKit/UIKit.h>
    #import <CoreLocation/CoreLocation.h>
    #import <MapKit/MapKit.h>
    
    @interface T20140621002009ViewController : UIViewController
    
    @property (weak, nonatomic) IBOutlet UITextField *txtQueryKey;
    
    @property (weak, nonatomic) IBOutlet UITextView *txtView;
    
    - (IBAction)geocodeQuery:(id)sender;
    
    @end
    #import "T20140621002009ViewController.h"
    
    @interface T20140621002009ViewController ()
    
    @end
    
    @implementation T20140621002009ViewController
    
    - (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 *urlString = [NSString stringWithFormat:
                                       @"http://maps.google.com/maps?q=%f,%f",
                                       coordinate.latitude,
                                       coordinate.longitude];
                
                NSURL *url = [NSURL URLWithString:urlString];
                
                [[UIApplication sharedApplication] openURL:url];
                
            }
        }];
        
        //关闭键盘
        [_txtQueryKey resignFirstResponder];
        
    }
    
    @end
  • 相关阅读:
    《C语言笔记:linux下C程序的内存映像》
    《C语言笔记:结构体内存对齐》
    《C语言笔记:一些自实现的字符串函数》
    《C语言笔记:大小端模式》
    《将博客搬至CSDN》
    《C语言笔记:三种内存来源》
    使用vue-cli3的方式创建项目并引入vant
    tomcat部署多个项目
    jenkins构建项目失败
    tomcat安装
  • 原文地址:https://www.cnblogs.com/cqchen/p/3802291.html
Copyright © 2011-2022 走看看