【发布时间】:2015-05-25 15:42:20
【问题描述】:
我正在使用适用于 ios 的谷歌地图 SDK。我想在屏幕中心固定一个标记,所以当用户拖动地图时,标记不会移动并停留在中心。我也试图在拖动后读取中心的坐标。任何输入将不胜感激。谢谢!
【问题讨论】:
标签: ios iphone google-maps fixed drag
我正在使用适用于 ios 的谷歌地图 SDK。我想在屏幕中心固定一个标记,所以当用户拖动地图时,标记不会移动并停留在中心。我也试图在拖动后读取中心的坐标。任何输入将不胜感激。谢谢!
【问题讨论】:
标签: ios iphone google-maps fixed drag
【讨论】:
yourMapView.bringSubviewToFront(view: yourMarkerView)@Yini
创建GMSMapView的outlet,并在地图中心附加Image,顶部的搜索栏显示位置名称。
在Device上拖动地图,会触发GMSMapViewDelegate的2个委托方法。
func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition)
func mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition)
/** * Called repeatedly during any animations or gestures on the map (or once, if the camera is * explicitly set). This may not be called for all intermediate camera positions. It is always * called for the final position of an animation or gesture. */ func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) { print("didchange")> > returnPostionOfMapView(mapView: mapView) } /** * Called when the map becomes idle, after any outstanding gestures or animations have completed (or * after the camera has been explicitly set). */ func mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition) { print("idleAt") //called when the map is idle returnPostionOfMapView(mapView: mapView) } //Convert the location position to address func returnPostionOfMapView(mapView:GMSMapView){ let geocoder = GMSGeocoder() let latitute = mapView.camera.target.latitude let longitude = mapView.camera.target.longitude let position = CLLocationCoordinate2DMake(latitute, longitude) geocoder.reverseGeocodeCoordinate(position) { response , error in if error != nil { print("GMSReverseGeocode Error: \(String(describing: error?.localizedDescription))") }else { let result = response?.results()?.first let address = result?.lines?.reduce("") { $0 == "" ? $1 : $0 + ", " + $1 } self.searchBar.text = address } } }
【讨论】: