Question

I have an app that gives a user there current location via reverse geocode using the following.

-(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];

}

This works perfectly. What i want to know is there a way to give location coordinates that are previously saved and then basically run the same process? I have looked at the apple docs and every thing i can find refers to using current location. I am hopping that there is a way to create a location under CLLocation and set my own long and Latt but i can't seem to find a reference that leads me in the right direction.

Was it helpful?

Solution

float longitude = Your saved longitude;
float latitude = Your saved latitude;

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

Now use location in your code instead of 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);
}

}];

May be it will work for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top