CLGeocoder返回其他国家的地点

我有以下代码:

CLGeocoder *_geo = [[CLGeocoder alloc] init]; CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter: CLLocationCoordinate2DMake(37.33233141, -122.03121860) radius:100 identifier:@"San Francisco"]; [_geo geocodeAddressString:@"Starbucks" inRegion:region completionHandler:^(NSArray *placemarks, NSError *error) { NSLog("%@", placemarks); }]; 

即使该中心位于旧金山的中心,这也会返回菲律宾的星巴克酒店。

 (NSArray *) $3 = 0x07cd9d10 <__NSArrayM 0x7cd9d10>( Starbuck's, Metro Manila, Quezon City, Republic of the Philippines @ <+14.63617752,+121.03067530> +/- 100.00m, region (identifier <+14.63584900,+121.02951050> radius 166.35) <+14.63584900,+121.02951050> radius 166.35m ) 

有任何想法吗?

虽然看起来不太可能,但似乎无论是a)苹果公司不打算在地区附近提供地理编码商业名称,或b)这是一个错误。

CLGeocoder参考在其概述中指出:

转发地理编码请求获取用户可读的地址并find相应的经度和纬度值…

这肯定意味着一个真正的物理地址作为searchstring(特别是“用户可读的地址”部分)。 但是, geocodeAddressString: inRegion: completionHandler:的文档指出searchstring是:

描述您要查找的位置的string…

这更加模糊。 我试着运行你的代码,代码非常相似,通过我的几个项目,我得到了相同的结果。 即使苹果公司的 GeocoderDemo样本也存在这个问题(尽pipe我住在加利福尼亚距离你的纬度/距离只有150英里),所以我们当然也没有写过任何东西。

我着手寻求帮助你解决这个问题! 但是,这一点是研究是我所有的。 祝你好运。

这是一个解决scheme,正在为我工​​作。 我正在使用geocodeAddressString: completionHandler:不考虑区域。

之后,我根据返回的地标build立一系列地标,但只包括最近的地标。

请注意,此代码不检查是否有错误。 我已经删除它,使其更简单。

 CLLocation *centerLocation = [[CLLocation alloc] initWithLatitude:37.33233141 longitude:-122.03121860]; CLLocationDistance maxDistance = <YOUR_MAX_DISTANCE>; CLGeocoder *geo = [[CLGeocoder alloc] init]; [geo geocodeAddressString:addressString completionHandler:^(NSArray *placemarks, NSError *error) { NSMutableArray *filteredPlacemarks = [[NSMutableArray alloc] init]; for (CLPlacemark *placemark in placemarks) { if ([placemark.location distanceFromLocation:centerLocation] <= maxDistance) { [filteredPlacemarks addObject:placemark]; } } // Now do whatever you want with the filtered placemarks. }]; 

或者,如果您想继续使用区域:而不是将距离与distanceFromLocation:进行比较,则可以使用CLRegioncontainsCoordinate: CLRegion

希望能帮助到你。

遇到同样的问题。 我已经提交了一个苹果的错误。 一旦我得到答案,会在这里更新你。

我解决了你的答案。 你在翻转GPS坐标的时候有一个错误。 如果你像这样改变它们,查询的效果很好!

http://maps.googleapis.com/maps/api/geocode/json?bounds=37.832331,-121.531219|36.832331,-122.531219&language=en&address=starbucks&sensor=true