CLGeocoder从给定位置进行反向地理编码 [英] CLGeocoder reverse geocode from given location
本文介绍了CLGeocoder从给定位置进行反向地理编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出经度和纬度不是我当前的位置?如何使用GLGeocoder
执行反向地址解析?
Given a longitude and latitude not my current location how can I perform a reverse geocode lookup using GLGeocoder
?
self.geoCoder = [[CLGeocoder alloc] init];
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
// [self.locationManager startUpdatingLocation];
[self.geoCoder reverseGeocodeLocation: locationManager.location completionHandler: ^(NSArray *placemarks, NSError *error) {
// [self.locationManager stopUpdatingLocation];
CLPlacemark *placemark = [placemarks objectAtIndex:0];
// Long address
// NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
// Short address
NSString *locatedAt = [placemark subLocality];
cell.textLabel.text = spot.name;
cell.detailTextLabel.text = [NSString stringWithFormat:@"Cab no: %@, spotted at %@", spot.cabno, locatedAt];
}];
很明显,只会对我的位置进行地理编码,但是我需要明确设置经度和纬度以反向.
Will obviously only ever geocode my location, but I need to explicitly set the longitude and latitude to reverse from.
推荐答案
我从没有尝试过,但是您不能创建自己的CLLocation对象吗?
I never tried this, but can't you create your own CLLocation object?
如果您知道当前的经度和纬度,则可以-
If you know current longitude and latitude you can -
CLLocation *location = [[CLLocation alloc]initWithLatitude:someValue longitude:someValue];
[self.geoCoder reverseGeocodeLocation: location completionHandler: ^(NSArray *placemarks, NSError *error) {
//do something
});
这篇关于CLGeocoder从给定位置进行反向地理编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文