我在iOS中使用Core Location来获取GPS坐标。我想得到一些人类可读的文本描述,这些坐标所在的一般区域。我可以在设备本身的本地或在我提交坐标的基于PHP的网站上完成这项工作。
有什么想法吗?
您可以创建URL来检索一组坐标的文本描述,如下所示:
http://maps.google.com/maps/geo?q="纬度"、"经度"&输出=csv&传感器=错误
E.Ghttp://maps.google.com/maps/geo?q=37.42228990140251,-122.082035425683&输出=csv&传感器=错误
您可以使用MKReverseGeocoder在设备本身的iOs中执行反向地理编码:http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKReverseGeocoder_Class/Reference/Reference.html#//apple_ref/occ/cl/MKReverseGeocoder
您可以在这里看到一些示例用法。
我在应用程序中使用CLLocationManagerDelegate和MKReverseGeocodeDelegate。创建CLLocationManager*位置管理器设置其属性和准确性,然后启动。
- (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
您将获得带有位置信息的NSDictionary。我没有用过所有的钥匙。如果您需要超过列出的NSLOG字典键及其响应值。希望它能帮助你。
- (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];
}