gpt4 book ai didi

ios - 如何自定义 Google Maps for iOS Swift 的 "myLocationButton"

转载 作者:搜寻专家 更新时间:2023-10-30 22:28:21 24 4
gpt4 key购买 nike

我是 iOS 开发的新手。我想创建一个自定义按钮,其功能与 Google Maps SDK for iOS 中的默认按钮 (myLocationButton) 相同。我可以这样做吗?我可以创建按钮,但我不知道如何添加操作来跟踪我的当前位置并在屏幕中央显示标记。我正在使用 Swift 3。

-Here is the image-

如有任何帮助,我们将不胜感激!

最佳答案

你可以像这样实现这个 Action :

func gotoMyLocationAction(sender: UIButton)
{
guard let lat = self.mapView.myLocation?.coordinate.latitude,
let lng = self.mapView.myLocation?.coordinate.longitude else { return }

let camera = GMSCameraPosition.camera(withLatitude: lat ,longitude: lng , zoom: zoom)
self.mapView.animate(to: camera)
}

这会将您的 map 居中到您当前的位置(如果存在)。希望有所帮助。

确保您的GMSMapView 上的位置检测已启用

self.mapView.isMyLocationEnabled = true

关于ios - 如何自定义 Google Maps for iOS Swift 的 "myLocationButton",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41040883/

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