我正在尝试使用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将我带入泰国
我是否误用“inRegion”
这适合任何人吗?因为如果它什么时候会很棒
答案 0 :(得分:0)
好的,答案。
不,它没有。它首先使用区域作为搜索的地方。来自API:
通过指定区域,您可以将返回的结果集划分给接近某个特定地理区域(通常是用户当前位置)的位置的优先级。
一切都好。
Got Placemark:Starbuck Dr,Sausalito CA 94965,United States @&lt; + 37.86315000,-122.57986000&gt; +/- 100.00m,区域(标识符&lt; + 37.86315000,-122.57986000&gt; radius 282.92)&lt; + 37.86315000,-122.57986000&gt;半径282.92m
我的建议是检查您所在地区的中心与地标中心之间的距离,并从服务器返回。