【发布时间】:2017-10-08 04:57:18
【问题描述】:
我在使用谷歌地图标记时遇到问题,我想将标记放在触摸上,但我不知道如何处理我尝试了几种方法,但它不起作用,然后我触摸地图没有任何反应。 pressrecognizer 好像有问题。
更新:
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 吗?
-
是的,你是对的
-
我试过了,当我点击地图时没有任何反应
-
你能告诉我更多代码吗?
-
更新了我的问题
标签: swift google-maps google-maps-markers