没有得到JSON响应谷歌查询经度和纬度在iOS? [英] Not getting json response in google query of longitude and latitude in iOS?
问题描述
我是iOS新手,所以如果有任何帮助,将不胜感激。
我想从地址中获取经度和纬度,之前的代码工作正常,但现在JSON数据将变为空。
这里我的示例代码,
url = [NSString stringWithFormat:@http://maps.google.com/maps/api/geocode/json ?地址=%@&安培;传感器=假,appDelegate.sAddress];
url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@地址URL:%@,url);
//将字符串表示为URL对象。
NSURL * requestURL = [NSURL URLWithString:url];
NSData * data = [NSData dataWithContentsOfURL:requestURL];
NSString * returnString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@my Coordinate:%@,returnString);
NSError *错误;
NSDictionary * json = [NSJSONSerialization
JSONObjectWithData:data
options:kNilOptions
error:& error];
但是我得到的输出为空。
>感谢你的回复,所有这些让我学到了很多东西。
作为我的朋友之一,告诉我解决方案,以便我与您分享。
以下是代码,
url = [NSString stringWithFormat:@http://maps.google.com/maps/api/geocode/json?address=%@&sensor=false appDelegate.sAddress];
url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@地址URL:%@,url);
//将字符串表示为URL对象。
NSURL * requestURL = [NSURL URLWithString:url];
NSData * data = [NSData dataWithContentsOfURL:requestURL];
NSString * returnString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
SBJSON * parser = [[SBJSON alloc] init];
NSDictionary * locationResult = [解析器objectWithString:returnString];
// [reverseGeoString copy]`
其工作正常。
但仍然存在一个问题,为什么会发生这种情况。早些时候,代码工作正常,但它突然停止工作。
I am new to iOS, so if any help it will be appreciated. I am trying to get the longitude and latitude from address, earlier the code was working fine but now the JSON data are coming null.
Here my sample code,
url = [NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?address=%@&sensor=false",appDelegate.sAddress];
url=[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"Address URL: %@",url);
//Formulate the string as a URL object.
NSURL *requestURL=[NSURL URLWithString:url];
NSData* data = [NSData dataWithContentsOfURL: requestURL];
NSString *returnString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"my Coordinate : %@",returnString);
NSError* error;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:data
options:kNilOptions
error:&error];
But i am getting the output as null.
So please help me out.
Thanks!
Thanks for your replies that all make me learn a lots. As one of my friend just tell me the solution so i am sharing with you.
Here is the code,
url = [NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?address=%@&sensor=false",appDelegate.sAddress];
url=[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"Address URL: %@",url);
//Formulate the string as a URL object.
NSURL *requestURL=[NSURL URLWithString:url];
NSData* data = [NSData dataWithContentsOfURL: requestURL];
NSString *returnString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *locationResult = [parser objectWithString:returnString];
//[reverseGeoString copy]`
And its working fine.
But still there is a question that why this happen.As earlier that code is working fine but it suddenly stopped working.
这篇关于没有得到JSON响应谷歌查询经度和纬度在iOS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!