Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nomar383

macrumors 65816
Original poster
Jan 29, 2008
1,310
0
Rexburg, ID
Hey guys,

So I've been googling and looking through some of the documentation for Core Location and I can't seem to find a good way to do what I want. I need to basically get what state the user is currently in (CA, AZ, ID, etc). What is the best way of doing so? All I can see is how to get the lat, long. Thanks in advance for any advice you can lend.
 
I'm pretty sure if you want that sort of thing then you have to provide it yourself (or find some web service that will do it). CL will not do it by itself
 
You cannot do that using CL. If you're targeting for OS 3.0, you can use a MKReverseGeocoder object to gain the address data near the coordinate. However, if you want to keep supporting 2.0, you will have to create a request to the Google Maps API and parse the returned XML all by yourself.
 
You cannot do that using CL. If you're targeting for OS 3.0, you can use a MKReverseGeocoder object to gain the address data near the coordinate. However, if you want to keep supporting 2.0, you will have to create a request to the Google Maps API and parse the returned XML all by yourself.

I'm going to develop this exclusively for 3.0 anyways, so I can use MKReverseGeocoder. Can anyone give me a brief example of how this would work?
 
Just from the docs:
Code:
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
   NSLog(@"US state is %@", placemark.administrativeArea);
   
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
{
   //alert user of failure
}

...

// to start lookup
MKReverseGeocoder *reverseGeocoder = [[MKReverseGeocoder alloc] initWithCoordinate:<CLLocationCoordinate2D you are interested in>];
reverseGeocoder.delegate = self;
[reverseGeocoder start];
 
Just from the docs:
Code:
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
   NSLog(@"US state is %@", placemark.administrativeArea);
   
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
{
   //alert user of failure
}

...

// to start lookup
MKReverseGeocoder *reverseGeocoder = [[MKReverseGeocoder alloc] initWithCoordinate:<CLLocationCoordinate2D you are interested in>];
reverseGeocoder.delegate = self;
[reverseGeocoder start];

I'm getting a "cannot find protocol declaration for 'MKReverseGeocoderDelegate'" error

I have a feeling it has something to do with my import statements. WHich ones should I have and where exactly should they be. I added the CoreLocation and MapKit frameworks to my project.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.