我正在尝试使用 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
示例 key 是虚拟 key 。尝试使用您自己的 key 。
我在我的应用程序中试过了。它工作正常。
关于iphone - 在 iOS 中从 Google 的 GEOLocation 获取 ZERO_RESULTS 响应。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9464045/