私はGoogleマップマーカーに問題がありますが、私はマーカーをタッチしたいと思いますが、それを処理する方法はわかりませんいくつかの方法を試しましたが、地図上でタッチします。 pressrecognizerで何か問題があるようです。スウィフト3 Googleマップはタッチでマーカーを追加します
更新日:
class MainMapController: UIViewController, CLLocationManagerDelegate {
@IBOutlet weak var viewMap: GMSMapView!
var makers: [GMSMarker] = []
var locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
initializeTheLocationManager()
self.viewMap.isMyLocationEnabled = true
let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress))
self.viewMap.addGestureRecognizer(longPressRecognizer)
}
func handleLongPress(recognizer: UILongPressGestureRecognizer)
{
if (recognizer.state == UIGestureRecognizerState.began)
{
let longPressPoint = recognizer.location(in: self.viewMap);
let coordinate = viewMap.projection.coordinate(for: longPressPoint)
let marker = GMSMarker(position: coordinate)
marker.opacity = 0.6
marker.title = "Current Location"
marker.snippet = ""
marker.map = viewMap
makers.append(marker)
}
}
func initializeTheLocationManager()
{
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
var location = locationManager.location?.coordinate
cameraMoveToLocation(toLocation: location)
locationManager.stopUpdatingLocation()
}
func cameraMoveToLocation(toLocation: CLLocationCoordinate2D?) {
if toLocation != nil {
viewMap.camera = GMSCameraPosition.camera(withTarget: toLocation!, zoom: 15)
}
}
です。viewMapはGMSMapViewですか? –
はいいいえ –
私は試しましたが、地図上でタップしても何も起こりません –