iPhone - Get City name from Latitude and Longtiude

前端 未结 10 932
难免孤独
难免孤独 2020-12-05 06:04

I want get my Current City name in my iPhone App.

I\'m currently getting the latitude and longitude using CLLocationManager and than i am passing my coordinates into

10条回答
  •  一生所求
    2020-12-05 06:17

    I am using this and getting the ZIP code and City Name. Modified the method added by Janak.

    - (void) getAddressFromLatLon:(CLLocation *)bestLocation
    {
        NSLog(@"%f %f", bestLocation.coordinate.latitude, bestLocation.coordinate.longitude);
        CLGeocoder *geocoder = [[CLGeocoder alloc] init] ;
        [geocoder reverseGeocodeLocation:bestLocation
                       completionHandler:^(NSArray *placemarks, NSError *error)
        {
            if (error){
                NSLog(@"Geocode failed with error: %@", error);
                return;
            }
            CLPlacemark *placemark = [placemarks objectAtIndex:0];
            NSLog(@"placemark.ISOcountryCode %@",placemark.ISOcountryCode);
            NSLog(@"locality %@",placemark.locality);
            NSLog(@"postalCode %@",placemark.postalCode);
    
        }];
    
    }
    

提交回复
热议问题