我有以下代码:
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
)
有任何想法吗?
虽然它似乎不太可能,它肯定会出现,要么一)苹果没有在前进地理编码企业名称打算一个区域附近,或b)这是一个错误。
该CLGeocoder参考 ,在其概述,指出:
正向地理编码请求采取用户可读地址,并找到相应的纬度和经度值...
这当然意味着真实物理地址作为搜索字符串(特别是“用户可读地址”的一部分)。 然而,对于文档geocodeAddressString: inRegion: completionHandler:
指出搜索字符串是:
...描述要查找的位置的字符串...
这更加模糊。 我试图运行你的代码,代码非常相似,它通过一对夫妇的我的项目,我也得到了相同的结果。 即使是苹果的 GeocoderDemo样品表现出的问题(虽然我住在加州,从刚刚〜150英里你的经/纬度为例),所以它肯定是没有我们两个都写。
我开始寻找解决这个问题的/你! 但是,是研究此位是我的一切。 祝您好运。
这里是为我工作一个解决方法。 我使用geocodeAddressString: completionHandler:
不考虑区域考虑。
在那之后,我建立一个基于返回的一个,但只有其中包括最近的那些标数组。
请注意,这个代码不检查是否出现了错误。 我已删除它,使其更简单。
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:
你可以使用CLRegion
的containsCoordinate:
希望能帮助到你。
我定你的答案。 你有,你翻转GPS COORDS一个错误。 如果你改变他们这个样子,查询的伟大工程!
http://maps.googleapis.com/maps/api/geocode/json?bounds=37.832331,-121.531219|36.832331,-122.531219&language=en&address=starbucks&sensor=true