Question

At the moment I'm working on an application for the iPad, which at a certain point should show a list of cities with next to these cities the distance from the users current location.

I'm using a loop which uses a database I built earlier. This is the code:

NSString *address = [NSString stringWithFormat:@"%@, Nederland", [info2 objectForKey:@"stadsnaam"]];
    [self.geocoder geocodeAddressString:address completionHandler:^(NSArray *placemarks, NSError *error) {
        CLPlacemark *placemark = [placemarks objectAtIndex:0];
        CLLocation *location = placemark.location;
        CLLocationCoordinate2D firstLocation = location.coordinate;
        NSLog(@"%f,%f", firstLocation.latitude, firstLocation.longitude);
    }];

This piece of code is inside a for loop. But the first time it is run, it just returns 0.0000

The second time the loop is activated (and I'm sure it runs more than one time) it returns only the distance between the current location and the FIRST city.

The app gets the city names from this piece of code:[NSString stringWithFormat:@"%@, Nederland", [info2 objectForKey:@"stadsnaam"]]

Which I verified and works. I would like to avoid using the Google API because I will be making more than the maximum request a day probably XD

Any help is appreciated, please inform me if anything isn't completely clear and thanks in advance!

Was it helpful?

Solution

You need to read the documentation for -geocodeAddressString:completionHandler::

After initiating a forward-geocoding request, do not attempt to initiate another forward- or reverse-geocoding request.

You can use CLGeocoder's geocoding property to determine whether a geocoding operation is in progress.

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