【问题标题】:CLLocationManager geocodeAddressString:inRegion not working to constrain region (ios5)CLLocationManager geocodeAddressString:inRegion 无法限制区域 (ios5)
【发布时间】: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
> 
> ...

任何想法:

  1. 它认为我在新德里吗? (我认为答案是否定的 - 因为搜索具有相同 inRegion 的“All Star Donuts”会将我放在泰国

  2. 我是否误用了“inRegion”

  3. 这对任何人都有效吗?因为如果有的话会很棒

【问题讨论】:

  • 我找到了解决此问题的方法,方法是改用geocodeAddressString: completionHandler:。看看my solution 来回答一个非常相似的问题。

标签: iphone ios geocoding core-location


【解决方案1】:

好的,回答。

  1. 不,它没有。它只是使用区域作为首先搜索的地方。来自 API:

    指定区域可让您将返回的结果集优先考虑靠近某个特定地理区域的位置,这通常是用户的当前位置。

  2. 一切正常。

  3. 对于请求“星巴克”,它返回给我

    地标:Starbuck Dr, Sausalito CA 94965, United States @ +/- 100.00m,区域(标识符 半径 282.92)

所以看起来它有效。

我的建议是检查服务器返回的区域中心和地标中心之间的距离。

【讨论】:

  • 谢谢 - 很高兴知道它对您有效;我无法获得更好的结果,并转而使用 Google Places API(终于让它工作了)。有没有机会你可以试试“花旗银行”而不是星巴克,看看你能不能在索萨利托(而不是新德里)买到一个?
猜你喜欢
  • 1970-01-01
  • 2018-08-04
  • 1970-01-01
  • 1970-01-01
  • 2015-02-20
  • 1970-01-01
  • 2018-07-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多