2

我想使用谷歌地理编码来查找带有名称的地方纬度经度列表,我没有在 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";
}
4

3 回答 3

2

检查这个

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);
    }
}


参考:Google 地理编码 API

于 2013-05-14T10:20:40.987 回答
0

试试这个

NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",address];
于 2013-05-14T10:44:01.197 回答
0

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

于 2013-05-14T09:41:17.277 回答