iOS 官网文档 地图周边关键字搜索

来源:互联网 发布:知乎 鞘师里保 编辑:程序博客网 时间:2024/05/16 01:44

//加载搜索结果并且标实地点

-(void)loadSearch:(NSString *)query

{

    // Create and initialize a search request object.

//创建和初始化一个搜索请求对象

    MKLocalSearchRequest *request = [[MKLocalSearchRequestalloc] init];

    request.naturalLanguageQuery = query;

    request.region = self.mapView.region;

    

    // Create and initialize a search object.

//创建和初始化一个搜索对象

    MKLocalSearch *search = [[MKLocalSearchalloc] initWithRequest:request];

    

    // Start the search and display the results as annotations on the map.

//开始搜索和用大头针展示结果在地图上

    [search startWithCompletionHandler:^(MKLocalSearchResponse *response,NSError *error)

    {

        NSMutableArray *placemarks = [NSMutableArrayarray];

        for (MKMapItem *itemin response.mapItems) {

            [placemarks addObject:item.placemark];

        }

        //移除原来的大头针

        [self.mapViewremoveAnnotations:[self.mapViewannotations]];

//加入大头针

        [self.mapViewaddAnnotations:placemarks];


        if (placemarks.count ==0) {

            [ShareApp showAlertView:@"暂无搜索结果"];

        }

//        [self.mapView showAnnotations:placemarks animated:NO];

    }];

}

0 0
原创粉丝点击