获得ZERO_RESULTS来自谷歌的Google GEOLocation的响应.

Ani*_*ish 5 iphone google-maps objective-c xml-parsing

我正在尝试使用xcode实现谷歌的地理位置.当我用纬度和经度传递网址时,它会返回以下结果

<?xml version="1.0" encoding="UTF-8"?>
<GeocodeResponse>
 <status>ZERO_RESULTS</status>
</GeocodeResponse>
Run Code Online (Sandbox Code Playgroud)

但是当我直接浏览网址时.它给出了正确的结果.示例网址:http://maps.googleapis.com/maps/api/geocode/xml ? latlng = 68.56066,76.8803& _nsor = 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);
Run Code Online (Sandbox Code Playgroud)

我需要获得xml结果.我的代码有问题吗?当我在谷歌网站上检查ZERO_RESULTS时.他们这样提到..

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

任何的想法...

Sub*_*n P 0

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

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

使用用户 Gmail 帐户登录。转到左侧的 Services 标签并打开 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

示例密钥是虚拟的。请尝试使用您自己的密钥。

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