【问题标题】:iphone google geocoding request failediphone谷歌地理编码请求失败
【发布时间】:2013-05-14 09:36:44
【问题描述】:

我想使用谷歌地理编码来查找带有名称的地方纬度经度列表,我没有在 iphone 中使用它的经验,但在 android 中它只是调用 url。但是当我在 iphone 中尝试相同的操作时,它给了我“请求被拒绝”的错误。指导我如何将其集成到 iphone 中,或者我应该使用 BSForwardGeocoder 之类的库,我正在这样做

NSString *url = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?address=%@&sensor=true", locationString];
url = [url stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

NSURL *wurl = [NSURL URLWithString:url];
NSDictionary *dict =  [Json objectWithUrl:wurl];
NSLog(@"%@", dict);

它打印为

{
results =     (
);
status = "REQUEST_DENIED";
}

【问题讨论】:

标签: iphone ios geocoding


【解决方案1】:

检查一下

NSString *locationString = @"1600 Amphitheatre Parkway, Mountain View, CA";
NSString *url = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?address=%@&sensor=true", locationString];
url = [url stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

NSURL *wurl = [NSURL URLWithString:url];
NSData *data = [NSData dataWithContentsOfURL: wurl];

// Fail to get data from server
if (nil == data) {

    NSLog(@"Error: Fail to get data");
}
else{
    // Parse the json data
    NSError *error;
    NSDictionary *json = [NSJSONSerialization
                          JSONObjectWithData:data
                          options:kNilOptions
                          error:&error];

    // Check status of result
    NSString *resultStatus = [json valueForKey:@"status"];

    // If responce is valid
    if ( (nil == error) && [resultStatus isEqualToString:@"OK"] ) {

        NSLog(@"%@", json);
    }
}


参考:The Google Geocoding API

【讨论】:

    【解决方案2】:

    您需要注册一个密钥,并且必须将其用作请求中的参数。

    【讨论】:

    • 你能把我链接到教程吗
    【解决方案3】:

    试试这个

    NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",address];
    

    【讨论】:

      猜你喜欢
      • 2018-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多