首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不能将geoCoder的所有注释都放在地图上

不能将geoCoder的所有注释都放在地图上
EN

Stack Overflow用户
提问于 2015-06-03 17:10:09
回答 1查看 49关注 0票数 0
代码语言:javascript
复制
-(void)showLocalRestaurantsWithDishRated:(MKUserLocation *)userLocation {

 CLGeocoder *geoCoder = [[CLGeocoder alloc] init];

[[RestaurantController sharedInstance] getRestaurantsFromParse:^(NSMutableArray *restaurants) {
  NSLog(@"%@",restaurants);

    for (Restaurant *restaurant in restaurants) {
        NSLog(@"%@", restaurant.address);
        [geoCoder geocodeAddressString:restaurant.address completionHandler:^(NSArray *placemarks, NSError *error) {
            NSLog(@"%@",placemarks);


                for (MKPlacemark *placemark in placemarks) {


                    MKPlacemark *newPlaceMark = [[MKPlacemark alloc] initWithPlacemark:placemark];
                    MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
                    point.coordinate = newPlaceMark.coordinate;
                    point.title = restaurant.restaurantName;
                    point.subtitle = restaurant.address;


                CLLocationCoordinate2D location = CLLocationCoordinate2DMake(placemark.location.coordinate.latitude, placemark.location.coordinate.longitude);


                    MKCoordinateRegion region = self.mapView.region;
                    region.span.latitudeDelta = 0.01;
                    region.span.longitudeDelta = 0.01;
                    region.center = location;


                    [self.mapView setRegion:region animated:YES];
                    [self.mapView addAnnotation:point];

            }


        }];
    }
}];

}

restaurant.address中的地址如下:

  • 北大普罗沃分校,UT 84604
  • 2045 W中心St Provo,UT 84601
  • 1200N大学大道,UT 84604
  • 80W St Provo中心,UT 84601
  • 434 W中心St Provo,UT 84601

问题是只有第一个地址被添加到地图中。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-03 17:26:18

你需要重组你的代码。您希望先创建要添加到映射中的所有位置的数组。一旦有了它,然后调用addAnnotations (带有"s")来添加所有注释。您还需要根据所有位置的跨度计算区域,以确保地图显示所有位置。然后,在计算了跨越所有位置所需的区域之后,只需调用setRegion一次。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30626500

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档