iOS定位服务与地图开发(6)---使用程序外地图之调用谷歌Web地图

也可以借助于谷歌的web地图API进行开发地图应用程序,但这里所涉及的技术都是Web技术了,而非本地技术。

谷歌提供的地图查询URL形式如下:http://maps.google.com/maps?q=参数

示例实现:

- (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];

        }
        
    }];
}
原文地址:https://www.cnblogs.com/yaoxc/p/3723171.html