Core Location to get US States

Discussion in 'iOS Programming' started by nomar383, Sep 3, 2009.

  1. nomar383 macrumors 65816

    nomar383

    Joined:
    Jan 29, 2008
    Location:
    Rexburg, ID
    #1
    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.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    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
     
  3. HerQ macrumors newbie

    Joined:
    Jun 11, 2008
    Location:
    The Netherlands
    #3
    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.
     
  4. nomar383 thread starter macrumors 65816

    nomar383

    Joined:
    Jan 29, 2008
    Location:
    Rexburg, ID
    #4
    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?
     
  5. Thomas Harte macrumors 6502

    Joined:
    Nov 30, 2005
    #5
    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];
    
     
  6. nomar383 thread starter macrumors 65816

    nomar383

    Joined:
    Jan 29, 2008
    Location:
    Rexburg, ID
    #6
    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.
     

Share This Page