我CLGeocoder用来在地图上定位地址,并计算用户与整个地址的距离。
这是使用的部分代码CLGeocoder:
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
__block float distance;
__block CLLocation *location;
[geocoder geocodeAddressString:adresseFinal completionHandler:^(NSArray *placemarks, NSError *error) {
if ([placemarks count] > 0) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
location = placemark.location;
CLLocationCoordinate2D coordinate = location.coordinate;
distance = [userLocation distanceFromLocation:location];
[distanceArray addObject:[NSString stringWithFormat:@"%f", distance]];
MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
point.coordinate = coordinate;
point.title = tableNoms[i];
NSMutableArray *coords = [[NSMutableArray alloc] init];
[coords addObject:location];
[coords addObject:userLocation];
[self.mapView addAnnotation:point];
}
dispatch_group_leave(group);
}];
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试在没有互联网连接的情况下使用它时,出现以下错误:
无法确定当前的国家/地区代码:错误域= NSURLErrorDomain代码= -1009“ Internet连接似乎已脱机。” UserInfo = 0x7877f930 {NSErrorFailingURLStringKey = http://gsp1.apple.com/pep/gcc,_kCFStreamErrorCodeKey = 8,NSErrorFailingURLKey = http://gsp1.apple.com/pep/gcc,NSLocalizedDescription = Internet连接似乎已脱机。 ,_kCFStreamErrorDomainKey = 12,NSUnderlyingError = 0x7877ed30“ Internet连接似乎处于脱机状态。”}
我以为我可以在没有互联网的情况下使用本地化功能(使用GPS?)?
我是否需要更改代码中的某些内容才能使用它?
非常感谢 !
地理编码与地理位置不同。GPS用于确定您的地理位置,其结果是纬度/经度位置。地理编码是在该地理位置和相应的地址详细信息之间转换的过程。
虽然地理定位不需要Internet连接,但地理编码却需要,因为它是在Apple数据库上查找以查找地理定位的地址。
| 归档时间: |
|
| 查看次数: |
905 次 |
| 最近记录: |