Yin*_*ini 10 iphone google-maps fixed drag ios
我正在使用谷歌地图SDK for ios.我想在屏幕中央固定一个标记,因此当用户拖动地图时,标记不会移动并保持在中心位置.我也试图在拖动后读取中心的坐标.任何输入将不胜感激.谢谢!
创建 GMSMapView 的出口,并在地图中心和顶部的搜索栏附加 Image 以显示位置名称。
在 Device 上拖动地图,这将触发 GMSMapViewDelegate 的 2 个委托方法。
func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition)?
func mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition)?
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)/** * 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 } } }
| 归档时间: |
|
| 查看次数: |
2329 次 |
| 最近记录: |