高德地图作业二

在该方法中- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath,添加如下代码,即可简单实现不重复添加和移动到中心:

    /*

     遍历_annotations数组,如果有同名字符串就不添加到地图中

     */

    for (MAPointAnnotation *annotationS in _annotations) {

        if ([annotationS.title isEqualToString:annotation.title]) {

            return;

        }

        

    }

    //按annotation.coordinate为中心开始移动

    [_mapView setCenterCoordinate:annotation.coordinate animated:YES];

 

需要注意的是,该代码应该要放在添加 [_mapView addAnnotation:annotation]和  [_annotations addObject:annotation]之前。

posted on 2016-01-02 13:24  十一点前要睡觉的小寒  阅读(158)  评论(0编辑  收藏  举报