【发布时间】:2011-09-19 08:03:12
【问题描述】:
我在 iOS 中使用核心位置来获取 GPS 坐标。我想获得这些坐标所在的一般区域的一些人类可读的文本描述。我可以在设备本身本地执行此操作,也可以在我提交坐标的基于 PHP 的网站上执行此操作。
有什么想法吗?
【问题讨论】:
我在 iOS 中使用核心位置来获取 GPS 坐标。我想获得这些坐标所在的一般区域的一些人类可读的文本描述。我可以在设备本身本地执行此操作,也可以在我提交坐标的基于 PHP 的网站上执行此操作。
有什么想法吗?
【问题讨论】:
您可以创建 URL 来检索一组坐标的文本描述,如下所示:
http://maps.google.com/maps/geo?q="latitude","longtitude"&output=csv&sensor=false
E.G http://maps.google.com/maps/geo?q=37.42228990140251,-122.0822035425683&output=csv&sensor=false
【讨论】:
您可以使用 MKReverseGeocoder 在设备本身的 iO 中进行反向地理编码:http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKReverseGeocoder_Class/Reference/Reference.html#//apple_ref/occ/cl/MKReverseGeocoder
你可以看到一些sample usage here。
【讨论】:
我在我的应用程序中使用 CLLocationManagerDelegate 和 MKReverseGeocoderDelegate。创建CLLocationManager * locationManager 设置好它的属性和精度然后启动。
- (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];
}
【讨论】: