Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 3谷歌地图iOS SDK-通过触摸添加标记_Ios_Swift_Google Maps_Google Maps Sdk Ios - Fatal编程技术网

Swift 3谷歌地图iOS SDK-通过触摸添加标记

Swift 3谷歌地图iOS SDK-通过触摸添加标记,ios,swift,google-maps,google-maps-sdk-ios,Ios,Swift,Google Maps,Google Maps Sdk Ios,大家好 我的iOS应用程序中有一个谷歌地图,我想做的是当我轻触或长触时,在地图中添加一个标记,并将坐标保存在数组中 例如:在Android中,我使用方法mMap.setOnLongClickListener()并将这些标记保存在Latlng数组类型中 任何帮助都是有用的! 谢谢首先,您需要在您的GMSMapView中添加uiLongPressGestureRecognitor,并实现UIGestureDelegate协议,使其与GMSMapView的所有手势同时工作,然后在longPress操作

大家好
我的iOS应用程序中有一个谷歌地图,我想做的是当我轻触或长触时,在地图中添加一个标记,并将坐标保存在数组中
例如:在Android中,我使用方法
mMap.setOnLongClickListener()
并将这些标记保存在Latlng数组类型中

任何帮助都是有用的!
谢谢

首先,您需要在您的
GMSMapView
中添加
uiLongPressGestureRecognitor
,并实现
UIGestureDelegate
协议,使其与
GMSMapView
的所有手势同时工作,然后在longPress操作中,您应该转换触摸的
CGPoint
CLLocationCoordinate2D
中,剩余部分很小

以此为例

//
//  DashedOverlayViewController.swift
//  GoogleMapsExample
//
//  Created by Reinier Melian on 17/07/2017.
//  Copyright © 2017 Pruebas. All rights reserved.
//

import UIKit
import GoogleMaps
import GooglePlaces



class DashedOverlayViewController: UIViewController {

    @IBOutlet weak var mapView: GMSMapView!

    var arrayCoordinates : [CLLocationCoordinate2D] = []

    var longPressRecognizer = UILongPressGestureRecognizer()

    @IBAction func longPress(_ sender: UILongPressGestureRecognizer) {
        debugPrint("You tapped at YES")
        let newMarker = GMSMarker(position: mapView.projection.coordinate(for: sender.location(in: mapView)))
        self.arrayCoordinates.append(newMarker.position)
        newMarker.map = mapView
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        longPressRecognizer = UILongPressGestureRecognizer(target: self,
                                                           action: #selector(self.longPress))
        longPressRecognizer.minimumPressDuration = 0.5
        longPressRecognizer.delegate = self
        mapView.addGestureRecognizer(longPressRecognizer)

        mapView.isMyLocationEnabled = true
        mapView.settings.compassButton = true

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

extension DashedOverlayViewController : UIGestureRecognizerDelegate
{
    public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool
    {
        return true
    }
}

GMSMapView有一个委托,该委托具有以下方法:

  - (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate;

您应该使用
ui长按gestureRecognitizer
来执行此操作。它不会显示地图您需要在故事板中添加的地图是一个IBOutlet@QuickAccount123仍然为空,我尝试了mapView=view as!GMSMapView!我也得到了这个错误。在展开可选文件时意外发现nilvalue@QuickAccount123你需要将GMSMapView添加到你的故事板ViewController中记住这是一个如何制作你需要的东西的示例,如果你需要关于如何设置基本GoogleMaps iOS项目的帮助,请告诉我