我有代码一直给我一个“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;
感谢您的帮助!
答案 0 :(得分:0)
已被
取代stringWithContentsOfURL:encoding:error:
或
stringWithContentsOfURL:usedEncoding:error:
答案 1 :(得分:0)
因为纬度和经度已将变量设置为0.0。
答案 2 :(得分:0)
使用此选项删除弃用警告
NSString *locationStr = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlStr] encoding:NSUTF16BigEndianStringEncoding error:nil];
同时尝试使用不同的lat,因为它们可能与你的lat long有问题