我在iOS中使用Core Location来获取GPS坐标。我想获得这些坐标所在的一般区域的一些人类可读的文字描述。我可以在设备本地或我提交坐标的基于PHP的网站上本地执行此操作。
有什么想法吗?
答案 0 :(得分:3)
你可以创建URL来检索一组坐标的文本描述,如下所示:
http://maps.google.com/maps/geo?q=“纬度”,“经度”& output = csv& sensor = false
E.G http://maps.google.com/maps/geo?q=37.42228990140251,-122.0822035425683&output=csv&sensor=false
答案 1 :(得分:2)
您可以使用 MKReverseGeocoder 在设备本身的iO中进行反向地理编码:http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKReverseGeocoder_Class/Reference/Reference.html#//apple_ref/occ/cl/MKReverseGeocoder
您可以看到一些sample usage here。
答案 2 :(得分:0)
我在我的应用程序中使用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];
}