gpt4 book ai didi

Swift GoogleMaps fitBounds Zoom

转载 作者:搜寻专家 更新时间:2023-11-01 07:08:27 25 4
gpt4 key购买 nike

新编码器尝试在我的 View 中调整 GoogleMap。

我查了很多资料,得出了这个结论,但对我不起作用。

覆盖 func loadView() {

    var markerList = [GMSMarker]()

// Create a GMSCameraPosition
let camera = GMSCameraPosition.camera(withLatitude: 4.390205, longitude: 2.154007, zoom: 8)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
mapView.isMyLocationEnabled = true
view = mapView

mapView.settings.myLocationButton = true
//mapView.setMinZoom(10, maxZoom: 20)

//create markers
for loc in arrayOfMapStops {
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: loc.lat, longitude: loc.long)
marker.title = loc.address
marker.snippet = loc.type
if loc.type == "Entrega" {marker.icon = GMSMarker.markerImage(with: .green)}
else {marker.icon = GMSMarker.markerImage(with: .blue)}
marker.map = mapView
markerList.append(marker)
}

//fit map to markers
var bounds = GMSCoordinateBounds()
for marker in markerList {
bounds = bounds.includingCoordinate(marker.position)
}
let update = GMSCameraUpdate.fit(bounds)
mapView.moveCamera(update)
}

map 未使用适当的缩放比例进行调整。

image of situation

谁能帮我解决缩放问题?

提前致谢:)

最佳答案

我自己解决了这个问题。我使用 DispatchQueue 为我的 map 设置正确的缩放比例。

这是我的最终代码:

override func loadView() {

var markerList = [GMSMarker]()

// Create a GMSCameraPosition
let camera = GMSCameraPosition.camera(withLatitude: 40.4167 , longitude: -3.70325, zoom: 8)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
mapView.isMyLocationEnabled = true
view = mapView

mapView.settings.myLocationButton = true
//mapView.setMinZoom(10, maxZoom: 20)

//create markers
for loc in arrayOfMapStops {
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: loc.lat, longitude: loc.long)
marker.title = loc.address
marker.snippet = loc.type
if loc.type == "Entrega" {marker.icon = GMSMarker.markerImage(with: .green)}
else {marker.icon = GMSMarker.markerImage(with: .blue)}
marker.map = mapView
markerList.append(marker)
}

delay(seconds: 3) { () -> () in
//fit map to markers
var bounds = GMSCoordinateBounds()
for marker in markerList {
bounds = bounds.includingCoordinate(marker.position)
}
let update = GMSCameraUpdate.fit(bounds, withPadding: 100.0)
mapView.animate(with: update)
}
}

func delay(seconds: Double, completion:@escaping ()->()) {
let when = DispatchTime.now() + seconds
DispatchQueue.main.asyncAfter(deadline: when) {
completion()
}
}

:)

关于Swift GoogleMaps fitBounds Zoom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46607631/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com