gpt4 book ai didi

ios - 默认手势事件在谷歌地图中不起作用

转载 作者:行者123 更新时间:2023-11-30 12:31:01 24 4
gpt4 key购买 nike

我想在长按时添加标记,但我的 didLongPressAt 坐标事件不起作用。我使用其中的 print 语句进行测试。我已经在其中添加了 UIView 。我也使用了内置手势,但它们仍然不起作用。这是我的代码。请帮帮我。

var mapView=GMSMapView()

var camera = GMSCameraPosition()
let locationmanager = CLLocationManager()



override func viewDidLoad() {
super.viewDidLoad()

self.mapView.delegate=self


// Do any additional setup after loading the view.
self.locationmanager.delegate=self
self.locationmanager.desiredAccuracy=kCLLocationAccuracyNearestTenMeters
self.locationmanager.requestWhenInUseAuthorization()
self.locationmanager.startUpdatingLocation()

}


func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
self.showCurrentLocationOnMap()
self.locationmanager.stopUpdatingLocation()

}

func showCurrentLocationOnMap()
{
camera = GMSCameraPosition.camera(withLatitude: (self.locationmanager.location?.coordinate.latitude)!, longitude: (self.locationmanager.location?.coordinate.longitude)!, zoom: 15)
mapView = GMSMapView.map(withFrame: CGRect(x: CGFloat(0), y: CGFloat(0), width: CGFloat(myView.frame.size.width), height: CGFloat(myView.frame.size.height)), camera: camera)



mapView.settings.myLocationButton=true
mapView.isMyLocationEnabled=true

let marker = GMSMarker()
marker.position=camera.target
marker.snippet="My Current Location"
marker.appearAnimation=GMSMarkerAnimation.pop
marker.map=mapView
myView.addSubview(mapView)

}


func mapView(_ mapView: GMSMapView, didLongPressAt coordinate: CLLocationCoordinate2D) {
print (coordinate.latitude)
print(coordinate.longitude)
}

最佳答案

这里的问题是,您通过执行 mapView = GMSMapView.map(withFrame: CGRect(x: CGFloat(0), y: CGFloat(0), width: CGFloat(myView.frame. size.width), 高度: CGFloat(myView.frame.size.height)), 相机: 相机)
您在此处创建的新 GMSMapView 实例的委托(delegate)未设置为 self。因此委托(delegate)方法(didLongPressAt)不会被调用。

相反,如果您只想在当前位置出现时重新定位相机,请使用 mapView.animate(withcameraUpdate: GMSCameraUpdate)

override func viewDidLoad() {
super.viewDidLoad()
let camera = GMSCameraPosition.camera(withLatitude: (self.locationmanager.location?.coordinate.latitude)!, longitude: (self.locationmanager.location?.coordinate.longitude)!, zoom: 15)

mapView = GMSMapView.map(withFrame: CGRect(x: CGFloat(0), y: CGFloat(0), width: CGFloat(myView.frame.size.width), height: CGFloat(myView.frame.size.height)), camera: camera)
self.mapView.delegate=self


// Do any additional setup after loading the view.
self.locationmanager.delegate=self
self.locationmanager.desiredAccuracy=kCLLocationAccuracyNearestTenMeters
self.locationmanager.requestWhenInUseAuthorization()
self.locationmanager.startUpdatingLocation()

}

func showCurrentLocationOnMap()
{
let newLocation = CLLocationCoordinate2D(latitude: self.locationmanager.location?.coordinate.latitude, self.locationmanager.location?.coordinate.longitude: longitude)
let cameraPositionUpdate = GMSCameraUpdate.setTarget(newLocation)
self.mapView.animate(with: cameraPositionUpdate)

// Code to add the marker
}

关于ios - 默认手势事件在谷歌地图中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43558650/

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