我想使用谷歌地理编码来查找地名纬度经度名单的列表,我没有在iphone中使用它的经验,但在android中它只是调用网址。但是当我在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";
}
答案 0 :(得分: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);
}
}
答案 1 :(得分:0)
您需要注册一个密钥,并且必须在请求中将其用作参数。
答案 2 :(得分:0)
尝试这个
NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",address];