在Google地图上显示多个位置。 IOS / Objective-C的

时间:2015-08-29 22:16:25

标签: ios objective-c google-maps

我使用谷歌地图sdks在IOS应用程序上显示我正在处理的位置。显示单个位置工作正常,但是当我尝试在单个地图上显示多个位置时,它会显示白色屏幕。我有一个 restaurantsData 对象,其中包含与一系列餐馆有关的信息(以及每个餐馆的纬度和经度)。现在尝试下面的代码时,它会显示一个白色的屏幕这是我第一次使用Google地图进行IOS,请帮帮我。

Restaurant *res = [[Restaurant alloc] init];

for (res in _restaurantData) {
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude: [res.objectLocation.lat doubleValue]
                                                            longitude: [res.objectLocation.lng doubleValue] zoom: 5];

    GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];

    GMSMarker *marker = [ [GMSMarker alloc] init];
    marker.position = CLLocationCoordinate2DMake([res.objectLocation.lat doubleValue], [res.objectLocation.lng doubleValue]);
    marker.appearAnimation = kGMSMarkerAnimationPop;
    marker.icon = [UIImage imageNamed:@"fork_filled"];
    marker.map = mapView;
}

1 个答案:

答案 0 :(得分:1)

你的循环必须像

for (Restaurant *res in _restaurantData) {
    GMSMarker *marker = [ [GMSMarker alloc] init];
    marker.position = CLLocationCoordinate2DMake([res.objectLocation.lat doubleValue], [res.objectLocation.lng doubleValue]);
    marker.appearAnimation = kGMSMarkerAnimationPop;
    marker.icon = [UIImage imageNamed:@"fork_filled"];
    marker.map = mapView;
}
相关问题