我需要一个坐标,例如,需要检查它是否距梅西百货商店或沃尔玛商店不到半英里。有没有一种方法,而不必存储每个沃尔玛/ macy商店的坐标,而只使用关键字“沃尔玛”或“ macys”?
您可以使用MKLocalSearch
。请注意,如果要同时搜索梅西百货和沃尔玛百货,则将使用两个不同的搜索对象进行两次搜索,因为如文档所述:
一个
MKLocalSearch
对象发起的基于地图的搜索操作,并提供结果返回给你的应用程序异步。搜索对象被设计为仅执行一项搜索操作。要执行几种不同的搜索,必须创建该类的单独实例并分别启动它们。
无论如何,基本代码如下所示:
// create new search request
MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init];
request.naturalLanguageQuery = @"Walmart";
request.region = mapView.region; // or create your `region` manually if not using a map
// initiate new search
MKLocalSearch *localSearch = [[MKLocalSearch alloc] initWithRequest:request];
[localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error) {
for (MKMapItem *item in response.mapItems) {
// do whatever you want with the results
}];
}];
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句