user2294134
user2294134

Reputation: 19

How to get ZipCode from latitude and longitude in iOS?

I am able to fetch latitude, longitude, city & address using CLLocationManagerDelegate. But i am unable to get ZipCode for some locations. Is there any way to get near by ZipCode using latitude and longitude?

Thanks in advance.

Upvotes: 1

Views: 3644

Answers (2)

Martijn
Martijn

Reputation: 470

  1. Create a CLLocation with the lat/long values you got from the locationManagerDelegate
  2. Instantiate a CLGeocoder and use - (void)reverseGeocodeLocation:(CLLocation *)location completionHandler:(CLGeocodeCompletionHandler)completionHandler (See reference)
  3. The completionhandler contains an NSArray placemark.
  4. One of the properties of a CLPlacemark is postalCode (See reference)

Upvotes: 5

thorb65
thorb65

Reputation: 2716

if the thePlacemark.postalCode is empty, you could try to increase the horizontal accuracy of the CLLocation with:

– initWithCoordinate:altitude:horizontalAccuracy:verticalAccuracy:timestamp:

Upvotes: 0

Related Questions