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
  • 相关阅读:
    Go学习2-切片
    Go学习1-MOD
    lua学习之逻辑运算符not,and,or
    google protobuf c++ 反射
    我要谴责一下,你们复制别人的答案好歹仔细看看
    远程登录redis
    openssl进行RSA加解密(C++)
    linux通过进程名查看其占用端口
    简体字丶冯|服务网关kong-docker安装
    简体字冯|docker-安装docker私有库
  • 原文地址:https://www.cnblogs.com/cqchen/p/3802291.html
Copyright © 2011-2022 走看看