Find latitude and longitude using CLGeocoder

3.3k views Asked by At

I am trying to find latitude and longitude by giving address string. I am getting 0.000 and 0.000 for both the values.

I am using MapKit, iOS 7, XCode 5

CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:@"Fairfax, VA" completionHandler:^(NSArray* placemarks, NSError* error){
    for (CLPlacemark* aPlacemark in placemarks)
    {
        CLLocationCoordinate2D coordinate;

        coordinate.longitude = aPlacemark.location.coordinate.longitude;
        coordinate.latitude = aPlacemark.location.coordinate.latitude;

        // updatedCoordinates is a property in my class and I am setting it's value 
        // here and using it in bunch of other places.
        self.updatedCoordinates = coordinate;
    }
}];
1

There are 1 answers

0
iKushal On
-(void)getPlacemarkInfo:(NSString*)placeName {
    // place name can be paris, etc
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder geocodeAddressString:placeName completionHandler:^(NSArray *placemarks, NSError *error) {
        if (error) {
            NSLog(@"%@", error);    
        } else {
            CLPlacemark *placemark = [placemarks lastObject];
     //     placemark.location.coordinate.latitude; will returns latitude
     //     placemark.location.coordinate.longitude; will returns longitude
        }
    }];
}