iphone - 在 iOS 中从 Google 的 GEOLocation 获取 ZERO_RESULTS 响应。

标签 iphone objective-c google-maps xml-parsing

我正在尝试使用 xcode 实现 google 的地理定位。当我传递带有纬度和经度的 url 时,它返回以下结果

<?xml version="1.0" encoding="UTF-8"?>
<GeocodeResponse>
 <status>ZERO_RESULTS</status>
</GeocodeResponse>

但是当我直接浏览 url 时。它给出了正确的结果。 示例网址:http://maps.googleapis.com/maps/api/geocode/xml?latlng=68.56066,76.8803&sensor=true

coord.latitude = 68.56066;
coord.longitude = 76.8803;

NSString *urlStr = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/xml?latlng=%f,%f&sensor=true",coord.latitude,coord.longitude];
       NSURL *url = [NSURL URLWithString:urlStr];


    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];


    NSData *xmlData = [NSData dataWithContentsOfURL:url];

    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
    NSString *str = [[NSString alloc]initWithData:xmlData encoding:NSUTF8StringEncoding];
      NSLog(@"XML Data is %@",str);

我需要获取 xml 结果。我的代码有什么问题吗。当我在谷歌网站上检查 ZERO_RESULTS 时。他们是这样提的..

ZERO_RESULTS 表示搜索成功但未返回任何结果。如果搜索是在远程位置传递 latlng,则可能会发生这种情况。

任何想法...

最佳答案

如果你想获得谷歌的地理定位服务,那么你需要获得访问 key 。

您可以使用以下网址获取访问 key https://code.google.com/apis/console/

使用用户gmail账号登录。转到左侧的服务标签并打开 place api 然后它会询问服务器名称并提供一些服务器名称。我给了http://facebook.com .之后转到左侧的 API 访问标签。它将显示所有启用的服务。在这里您可以获得类似于 AIMjkUluYsB1G2t5u5p0IIQmsHgiga5F0-8c 的 API KEY。在以下 URL 最后一个参数中使用该键。

XML 响应: http://maps.google.com/maps/geo?output=xml&oe=utf-8&ll=latitude,logitiude&key=AddYourOwnKeyHere

JSON 响应 http://maps.google.com/maps/geo?output=json&oe=utf-8&ll=latitude,logitiude&key=AddYourOwnKeyHere

例子: http://maps.google.com/maps/geo?output=xml&oe=utf-8&ll=12.922499,77.639354&key=AIMjkUluYsB1G2t5u5p0IIQmsHgiga5F0-8c

示例 key 是虚拟 key 。尝试使用您自己的 key 。

我在我的应用程序中试过了。它工作正常。

关于iphone - 在 iOS 中从 Google 的 GEOLocation 获取 ZERO_RESULTS 响应。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9464045/

相关文章:

iphone - UIToolbar UIBarButtonItem 对齐问题

java - 用作按钮的 Android 选项卡

javascript - Xamarin不允许加载本地资源文件

iphone - 从多个表中过滤数据

iphone - 如何重置 UIImageView 变换属性

ios - MasterPass 集成 iOS

ios - 直接从自定义 UITableViewCell 检查互联网连接

objective-c - 如何为选择多行时使用的 UITableViewCell 图像设置皮肤?

google-maps - Xamarin.Forms 中的 Google Place 自动完成

iphone - 如何根据 NSArray 中自定义对象的日期进行排序...?