相关疑难解决方法(0)

iOS,如何使用GMSCoordinateBounds显示地图的所有标记?

我想显示我地图上的所有标记,经过一些搜索我发现它应该用GMSCoordinateBounds(Google Maps SDK)完成我已经阅读了有关它的官方文档,但我还不明白如何使用它并在我的代码中实现它.

https://developers.google.com/maps/documentation/ios/reference/interface_g_m_s_camera_update#aa5b05606808272f9054c54af6830df3e

这是我的代码

GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] init];   
CLLocationCoordinate2D location;

for (NSDictionary *dictionary in array) {
    location.latitude = [dictionary[@"latitude"] floatValue];
    location.longitude = [dictionary[@"longitude"] floatValue];

    // Creates a marker in the center of the map.
    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.icon = [UIImage imageNamed:(@"marker.png")];
    marker.position = CLLocationCoordinate2DMake(location.latitude, location.longitude);
    bounds = [bounds includingCoordinate:marker.position];
    marker.title = dictionary[@"type"];
    marker.map = mapView_;
}   

[mapView_ animateWithCameraUpdate:[GMSCameraUpdate fitBounds:bounds withPadding:30.0f]];
Run Code Online (Sandbox Code Playgroud)

有帮助吗?

google-maps ios google-maps-sdk-ios

47
推荐指数
8
解决办法
4万
查看次数

标签 统计

google-maps ×1

google-maps-sdk-ios ×1

ios ×1