简体   繁体   中英

Get text description of region from GPS coordinates

I am using Core Location in iOS to get GPS coordinates. I would like to get some human readable text description of the general region where these coordinates are. I can do this either locally on the device itself or on a PHP-based website to which I am submitting the coordinates.

Any ideas?

you can create URL's to retrieve a text desription of a set of coordinates like this:

http://maps.google.com/maps/geo?q= "latitude","longtitude"&output=csv&sensor=false

EG http://maps.google.com/maps/geo?q=37.42228990140251,-122.0822035425683&output=csv&sensor=false

I use CLLocationManagerDelegate and MKReverseGeocoderDelegate in my app. Create CLLocationManager * locationManager set up its properties and accuracy then start.

- (void)locationManager:(CLLocationManager *)manager
       didUpdateHeading:(CLHeading *)newHeading 
{
    [manager stopUpdatingHeading];

    CLLocationCoordinate2D coordinate = manager.location.coordinate;

    MKReverseGeocoder * geocoder = [[MKReverseGeocoder alloc] initWithCoordinate:coordinate];
    geocoder.delegate = self;
    [geocoder start];
}

#pragma mark - MKReverseGeocoderDelegate

You'll get NSDictionary with location info. I've used no all keys. If you need more than listed NSLOG dictionary keys and its responsive values. Hope it will help you.

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
    getLocationState = glsAvailable;

    NSDictionary * dic = placemark.addressDictionary;

    NSString * CountryCode = [dic objectForKey:@"CountryCode"];
    NSString * State = [dic objectForKey:@"State"];
    NSString * City = [dic objectForKey:@"City"];
    NSString * SubLocality = [dic objectForKey:@"SubLocality"];
    NSString * Street = [dic objectForKey:@"Street"];
    NSString * ZIP = [dic objectForKey:@"ZIP"];

    self.locationString = [NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@",
                           CountryCode?CountryCode:@"",
                           State?State:@"",
                           City?City:@"",
                           SubLocality?SubLocality:@"",
                           Street?Street:@"",
                           ZIP?ZIP:@""
                           ];

    [[NSNotificationCenter defaultCenter] postNotificationName:@"LOCATION_STRING_IS_READY" object:nil];
    [geocoder cancel];
    [geocoder release];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM