您的位置:首页 > 移动开发 > IOS开发

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

2014-05-12 12:27 1061 查看
也可以借助于谷歌的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];

}

}];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: