我在iOS应用程序中使用Google Map服务GMSMapview。在那里我有两个CLLocationCoordinates。一个是当前位置,另一个是目的地位置。我试图在这两个地方安装地图。
但相机位置未设定在这两点之内。我尝试使用以下代码,
CLLocationCoordinate2D start = CLLocationCoordinate2DMake(newLoc.coordinate.latitude, newLoc.coordinate.longitude);
CLLocationCoordinate2D end = CLLocationCoordinate2DMake(_retailerVO.R_Latitude, _retailerVO.R_Longitude);
GMSCoordinateBounds *gBounds =
[[GMSCoordinateBounds alloc] initWithCoordinate:start coordinate:end];
GMSCameraPosition *gCamera = [mapView_ cameraForBounds:gBounds insets:UIEdgeInsetsZero];
mapView_.camera = gCamera;
有没有办法实现我想要的?所有建议都表示赞赏。
答案 0 :(得分:3)
添加带边界的填充,它适用于我,希望它可以帮助你,
GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:start coordinate:end];
[self.viewMapView animateWithCameraUpdate:[GMSCameraUpdate fitBounds:bounds withPadding:100.0f]];
答案 1 :(得分:1)
在Swift中
let bounds = GMSCoordinateBounds(coordinate: sourcePosition, coordinate: endPosition)
let camera: GMSCameraUpdate = GMSCameraUpdate.fit(bounds)
// let cameraWithPadding: GMSCameraUpdate = GMSCameraUpdate.fit(bounds, withPadding: 100.0) (will put inset the bounding box from the view's edge)
self.mapView.animate(with: camera)