【问题标题】:Can i use saved co-ordinates for reverse geocode?我可以使用保存的坐标进行反向地理编码吗?
【发布时间】: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


【解决方案1】:
float longitude = Your saved longitude;
float latitude = Your saved latitude;

CLLocation *location = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];

现在在您的代码中使用位置而不是 currentLocation

[geocoder reverseGeocodeLocation:location 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);
}

}];

也许它对你有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-26
    • 2018-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-21
    相关资源
    最近更新 更多