Iphone 谷歌地图API错误:";stringwithcontentsofurl不推荐使用;

Iphone 谷歌地图API错误:";stringwithcontentsofurl不推荐使用;,iphone,ios,objective-c,google-maps,development-environment,Iphone,Ios,Objective C,Google Maps,Development Environment,我的代码不断给我一个“stringwithcontentsofurl已弃用”错误,我不知道如何修复它。这个应用程序一直带我去谷歌地图,以0.0 lat,0.0 long显示海洋中心。这是我现在的密码 NSString *locationStr = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlStr]]; NSLog(@"locationstr:%@",locationStr); NSArray *items = [locat

我的代码不断给我一个“stringwithcontentsofurl已弃用”错误,我不知道如何修复它。这个应用程序一直带我去谷歌地图,以0.0 lat,0.0 long显示海洋中心。这是我现在的密码

NSString *locationStr = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlStr]];
NSLog(@"locationstr:%@",locationStr);
NSArray *items = [locationStr componentsSeparatedByString:@","];

double lat = 0.0;
double lon = 0.0;

if([items count] >= 4 && [[items objectAtIndex:0] isEqualToString:@"200"]) {
    lat = [[items objectAtIndex:2] doubleValue];
    lon = [[items objectAtIndex:3] doubleValue];
} else {
    NSLog(@"Address, %@ not found: Error %@",addressStr, [items objectAtIndex:0]);
}
NSLog(@"latlonislatlon:%.12f,%.12f,urlstr:%@",lat,lon,urlStr);
CLLocationCoordinate2D location;
location.latitude = lat;
location.longitude = lon;

谢谢你的帮助

它已被替换为

stringWithContentsOfURL:encoding:error: 


因为您的纬度和经度变量已设置为0.0。

使用此选项可删除弃用警告

NSString *locationStr = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlStr] encoding:NSUTF16BigEndianStringEncoding error:nil];

还可以尝试使用不同的lat,因为他们的lat long可能会出现问题,这是他们之前设置的,并且可以正常工作。应该设置为什么?@user2706002我不知道你应该设置为什么。不过我刚刚回答了你的问题。你的问题是为什么它显示坐标0,0。我回答了。你没看文档吗?如果你查一下这个方法,它会告诉你替换的是什么。@rdelmar哇,太粗鲁了。我只是请求帮助。没人说你必须回答。你本可以读到这篇文章然后继续。“如果你没有什么好说的,就什么都不要说”祝你有一个美好的一天,重点是,在寻求帮助之前,你应该先做你的研究。我的观点是,你什么都不需要说。再说一次,你本可以读到这篇文章,继续前进。很多其他人回答了这个问题,并试图提供帮助。很好的一天
NSString *locationStr = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlStr] encoding:NSUTF16BigEndianStringEncoding error:nil];