gpt4 book ai didi

swift - 谷歌地图缩放

转载 作者:行者123 更新时间:2023-11-30 10:29:07 25 4
gpt4 key购买 nike

我正在尝试在来自纬度的特定引脚上缩放谷歌地图。它工作正常,但我想在快速放大引脚时更改引脚图像。我已经这样做了,但在同一纬度上放置了 2 个图像长。

func zoom(lat: Double, long : Double){
CATransaction.begin()
CATransaction.setValue(1, forKey: kCATransactionAnimationDuration)

// It will animate your camera to the specified lat and long
let camera = GMSCameraPosition.camera(withLatitude: lat, longitude: long, zoom: 15)
self.mapView!.animate(to: camera)
let position = CLLocationCoordinate2D(latitude: lat,longitude: long)
let marker = GMSMarker()
marker.map = self.mapView
marker.icon = UIImage.init(named: "pin-1")

CATransaction.commit()
}

最佳答案

您可以放置​​一个函数来检测缩放级别的变化,然后放置一个条件来更改标记图标的值。

这是我的代码的样子:

import UIKit
import GoogleMaps

class ViewController: UIViewController, GMSMapViewDelegate {
let marker = GMSMarker()

override func viewDidLoad() {

}

override func loadView() {
// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 6.0)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
self.view = mapView

mapView.delegate = self

// Creates a marker in the coordinate of the map.

marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
marker.icon = UIImage(named: "pin_orange")
}

//This detect the changes in the cameraposition
func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
let zoom = mapView.camera.zoom
print("map zoom is ",String(zoom))

//put a condition here to change the icon of your marker
if zoom > 6 {
marker.icon = UIImage(named: "icon1")
}else{
marker.icon = UIImage(named: "icon2")
}
}
}

希望这有帮助!

关于swift - 谷歌地图缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59508478/

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