【发布时间】:2012-01-20 18:24:45
【问题描述】:
我正在尝试使用 iOS 5 中的新 CLLocationManager API 使用(转发)地理编码,但没有任何运气。
我正在根据当前位置指定一个区域,但它却在世界的另一端为我提供了结果。
//CLLocation *currentloc is set to the current location when I get in here (<+37.78583400,-122.40641700>)
CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:[currentloc coordinate] radius:5000 /*meters*/ identifier:@"You are here"];
// Region is now: (identifier You are here) <+37.78583400,-122.40641700> radius 5000.00m
NSString *addressString = @"Citibank"; //for example
[geoCoder geocodeAddressString:addressString inRegion:region completionHandler:^(NSArray* placemarks, NSError* error){
for (CLPlacemark* aPlacemark in placemarks)
{ // Process the placemark.
NSLog(@"Got Placemark : %@", aPlacemark);
}
}];
我得到的只是:
> 2011-12-14 15:50:49.882 [12377:12503] Got Placemark : Citibank, New
> Delhi, Delhi, India @ <+28.63470640,+77.22010140> +/- 100.00m, region
> (identifier <+28.63517750,+77.21878050> radius 154.35)
> <+28.63517750,+77.21878050> radius 154.35m
>
> 2011-12-14 15:50:49.883[12377:12503] Got Placemark : CitiBank, Noida,
> Uttar Pradesh, India @ <+28.58157180,+77.32408380> +/- 100.00m, region
> (identifier <+28.58161950,+77.32315050> radius 154.41)
> <+28.58161950,+77.32315050> radius 154.41m
>
> 2011-12-14 15:50:49.885 [12377:12503] Got Placemark : Citibank, New
> Delhi, Delhi, India @ <+28.53627320,+77.21128390> +/- 100.00m, region
> (identifier <+28.53630050,+77.21054050> radius 154.46)
> <+28.53630050,+77.21054050> radius 154.46m
>
> ...
任何想法:
它认为我在新德里吗? (我认为答案是否定的 - 因为搜索具有相同 inRegion 的“All Star Donuts”会将我放在泰国
我是否误用了“inRegion”
这对任何人都有效吗?因为如果有的话会很棒
【问题讨论】:
-
我找到了解决此问题的方法,方法是改用
geocodeAddressString: completionHandler:。看看my solution 来回答一个非常相似的问题。
标签: iphone ios geocoding core-location