4

A directions to a working example or some guidance on how to use the forward geocoding beside the Apple Documentation. Thats pretty generic (i cant understand)

Please this would be great! Also does anyone know if they are using Google API to achieve the same or their own?

carbonr
  • 6,049
  • 5
  • 46
  • 73
  • http://stackoverflow.com/questions/1140404/forward-geocoding-from-the-iphone/2444249#2444249, try that – iNoob Mar 19 '12 at 13:42
  • 1
    already did, one answer points to CLGeocoder but doesn't show anything. The solutions there are pre-iOS5. Now we have geocoding available as a built in solution. – carbonr Mar 19 '12 at 17:55

1 Answers1

11

Found this to work, though i will post it here if someone else finds it useful.

CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder geocodeAddressString:PlaceName.text completionHandler:^(NSArray *placemarks, NSError *error) {
        //Error checking

        CLPlacemark *placemark = [placemarks objectAtIndex:0];
        MKCoordinateRegion region;
        region.center.latitude = placemark.region.center.latitude;
        region.center.longitude = placemark.region.center.longitude;
        MKCoordinateSpan span;
        double radius = placemark.region.radius / 1000; // convert to km

        NSLog(@"Radius is %f", radius);
        span.latitudeDelta = radius / 112.0;

        region.span = span;

        [mapView setRegion:region animated:YES];
    }];
carbonr
  • 6,049
  • 5
  • 46
  • 73
  • 1
    According to the Map Kit Data Types Reference, under MKCoordinateSpan Apple notes: one degree of latitude is always approximately 111 kilometers (69 miles). Haven't verified whether this is true or not though. – redshift5 Oct 17 '12 at 02:04
  • @AliakseiN. i didn't notice your comment. 112 is not by magic. If you convert 1 degree to Km, you will get this – carbonr Oct 17 '12 at 13:20
  • @carbonr 1° latitude = 69.047 statute miles = 60 nautical miles = 111.12 kilometers – Aleks N. Oct 22 '12 at 16:16