geocodeAddressString is not running for the following address

1.3k views Asked by At

If i give any address for this method it is not at all calling.But if if give "1800 Ellis St,San Francisco, CA 94102,United States" it is being called. tell me what is wrong.

 [geocoder geocodeAddressString:@"#83 2nd Floor Diagonal Road V.V.Puram Bangalore 560004 India"
                     completionHandler:^(NSArray* placemarks1, NSError* error){
                         for (CLPlacemark* aPlacemark in placemarks1)
                         {
                             annotationCoord=  aPlacemark.location.coordinate;
                             [locationManager stopUpdatingLocation];
                             MKCoordinateRegion region;
                             region.center.latitude=annotationCoord.latitude;
                             region.center.longitude=annotationCoord.longitude;

                             region.span.longitudeDelta=0.;
                             region.span.latitudeDelta=0.;


                             self.mapView.showsUserLocation = YES;
                             [self.mapView setRegion:region];
                             _annotation=[[LDAnnotation alloc]initWithCoordinate:annotationCoord andTitle:@""subTitle:@""];
                             [self.mapView addAnnotation:(id<MKAnnotation>)_annotation];
                             [_searchAddressTF resignFirstResponder];
                         }
                     }];
1

There are 1 answers

3
timelincoln On BEST ANSWER

your placemarks1 array is probably empty, as you're not checking if it is or not, the block just isn't executing. This is the common format

[self.geocoder geocodeAddressString:address completionHandler:^(NSArray *placemarks, NSError *error) {
    if ([placemarks count] > 0) {
        CLPlacemark *placemark = [placemarks objectAtIndex:0];
        CLLocation *location = placemark.location;
        CLLocationCoordinate2D coordinate = location.coordinate;

you can try printing the size of the place marks. Check out this page if you haven't seen it already. http://code.tutsplus.com/tutorials/forward-geocoding-with-clgeocoder--mobile-11011