【发布时间】:2014-05-08 13:06:45
【问题描述】:
我有一个应用程序,它使用以下方法通过反向地理编码为用户提供当前位置。
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
NSLog(@"Location: %@", newLocation);
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
latitude = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];
longitude = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
//end hear for just long lat
}
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
if (error == nil && [placemarks count] >0) {
placemark = [placemarks lastObject];
self.addressLable.text = [NSString stringWithFormat:@"%@ %@\n%@ %@\n%@\n%@",
placemark.subThoroughfare, placemark.thoroughfare,
placemark.postalCode, placemark.locality,
placemark.administrativeArea,
placemark.country];
streetandNo = [NSString stringWithFormat:@"%@ %@", placemark.subThoroughfare,placemark.thoroughfare];
suberb = [NSString stringWithFormat:@"%@", placemark.locality];
}else {
NSLog(@"%@", error.debugDescription);
}
}];
[self performSelector:@selector(stopupdate) withObject:nil afterDelay:2.0];
}
这非常有效。我想知道有没有办法给出以前保存的位置坐标,然后基本上运行相同的过程?我查看了苹果文档,我能找到的每一件事都是指使用当前位置。我希望有一种方法可以在 CLLocation 下创建一个位置并设置我自己的 long 和 Latt,但我似乎找不到可以引导我走向正确方向的参考。
【问题讨论】:
-
您可以创建自己的 CLLocation 对象并将其保存以备将来使用。或者只是在 NSUserDefault 中保存 lat/long 值,并在需要时动态创建 CLLocation 对象。
标签: ios location reverse-geocoding