【问题标题】:Fixed marker on google maps for ios修复了 ios 谷歌地图上的标记
【发布时间】:2015-05-25 15:42:20
【问题描述】:

我正在使用适用于 ios 的谷歌地图 SDK。我想在屏幕中心固定一个标记,所以当用户拖动地图时,标记不会移动并停留在中心。我也试图在拖动后读取中心的坐标。任何输入将不胜感激。谢谢!

【问题讨论】:

    标签: ios iphone google-maps fixed drag


    【解决方案1】:

    我宁愿在 GMSMapView 上显示视图(不要为此使用标记)。由于您有地图视图的屏幕位置,因此应该很容易将您的视图放置在正确的位置。

    要获取坐标,您可以使用mapView.projection.coordinateForPoint

    文档是here

    要知道拖动完成,让您查看地图视图 (GMSMapViewDelegate) 的控制器(或任何其他对象)委托并实现 mapView:idleAtCameraPosition: 方法。

    文档是here

    【讨论】:

    • 谢谢皮奥特。我很难在 GMSMapView 上显示视图。我尝试使用“insertSubview”和“addSubview”,但只要设置“self.view = _mapView;”,标记视图就不会显示在顶部。
    • 先添加marker view 然后yourMapView.bringSubviewToFront(view: yourMarkerView)@Yini
    【解决方案2】:

    创建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
                }
            }
        }
    

    Github Demo Project

    【讨论】:

    • 在这种情况下使用位置管理器委托的区域是什么
    猜你喜欢
    • 2019-05-08
    • 1970-01-01
    • 2017-04-08
    • 2012-01-10
    • 2018-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多