设置谷歌地图为视图

问题描述 投票:1回答:1

在我完成设置谷歌地图后,我已经添加了三个子视图UIButton它的点击,我认为它的工作正常,和UIView和UIView的顶部,我已经添加了UITextField(子视图),但我不能使用它,我不能输入任何东西,它是不可编辑的,所以当我评论谷歌地图代码一切工作正常的文本字段,我,但在UIView将允许编辑工作正常。

import UIKit
import GoogleMaps

class GoogleMap: UIViewController, UITextFieldDelegate {

    let locationBtn: UIButton = {
        let button = UIButton(type: .system)
        button.addTarget(self, action: #selector(orderBtnAction), for: UIControl.Event.touchUpInside)
        button.setTitle("إستخدام هذا الموقع", for: UIControl.State.normal)
        button.titleLabel?.font =  UIFont.systemFont(ofSize: 15)
        button.tintColor = UIColor.white
        button.layer.cornerRadius = 10
        button.backgroundColor = UIColor.delevareColor
        button.translatesAutoresizingMaskIntoConstraints = false
       return button
    }()

    let locationView: UIView = {
        let view = UIView()
        view.layer.cornerRadius = 15
        view.backgroundColor = UIColor.white
        view.layer.shadowPath = UIBezierPath(rect: view.bounds).cgPath
        view.layer.shadowRadius = 5
        view.layer.shadowOffset = .zero
        view.layer.shadowOpacity = 1
        view.clipsToBounds = true
        view.translatesAutoresizingMaskIntoConstraints = false
        return view
    }()

    let currentLocTextField: UITextField = {
        let textField = UITextField()
        textField.text = "جاري تحميل موقعك..."
        textField.font = UIFont.boldSystemFont(ofSize: 19)
        textField.textColor = UIColor.black
        textField.borderStyle = .roundedRect
        textField.isUserInteractionEnabled = true
        textField.translatesAutoresizingMaskIntoConstraints = false
        textField.textAlignment = .center
        return textField
    }()

 var locationManager = CLLocationManager()
    var mapView: GMSMapView!

    override func viewDidLoad() {
        super.viewDidLoad()

        currentLocTextField.delegate = self
        locationView.addSubview(currentLocTextField)
        setUpNavigationController()
        setUpGoogleMap()
        setUpLayout()

    }

func setUpLayout() {

        locationBtn.heightAnchor.constraint(equalToConstant: 50).isActive = true
        locationBtn.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
        locationBtn.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -25).isActive = true
        locationBtn.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 10).isActive = true
        locationBtn.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -10).isActive = true

        locationView.heightAnchor.constraint(equalToConstant: 120).isActive = true
         locationView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
        locationView.bottomAnchor.constraint(equalTo: locationBtn.topAnchor, constant: -10).isActive = true
        locationView.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 10).isActive = true
        locationView.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -10).isActive = true

        currentLocTextField.heightAnchor.constraint(equalToConstant: 30).isActive = true
        currentLocTextField.centerXAnchor.constraint(equalTo: locationView.centerXAnchor).isActive = true
        currentLocTextField.topAnchor.constraint(equalTo: locationView.topAnchor, constant: 20).isActive = true
        currentLocTextField.leftAnchor.constraint(equalTo: locationView.leftAnchor, constant: 20).isActive = true
        currentLocTextField.rightAnchor.constraint(equalTo: locationView.rightAnchor, constant: -50).isActive = true

        }

    func setUpGoogleMap(){

        let camera = GMSCameraPosition.camera(withLatitude: 15.592778, longitude: 32.552278, zoom: 12)
        mapView = GMSMapView.map(withFrame: .zero, camera: camera)
        view = mapView
        mapView.animate(to: camera)
        mapView.isMyLocationEnabled = true
        locationManager.delegate = self
        locationManager.requestWhenInUseAuthorization()
        mapView.delegate = self
        mapView.addSubview(locationBtn)
        mapView.addSubview(locationView)

    }

}

extension GoogleMap: CLLocationManagerDelegate {
  func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {

    guard status == .authorizedWhenInUse else {

      return
    }

    locationManager.startUpdatingLocation()


    mapView.isMyLocationEnabled = true
    mapView.settings.myLocationButton = true
  }


  func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    guard let location = locations.first else {
      return
    }

    // 7
    mapView.camera = GMSCameraPosition(target: location.coordinate, zoom: 15, bearing: 0, viewingAngle: 0)

    // 8
    locationManager.stopUpdatingLocation()
  }
}
extension GoogleMap: GMSMapViewDelegate {

    func mapView(_ mapView: GMSMapView, willMove gesture: Bool) {
     return
    }
  func mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition) {
    if #available(iOS 11.0, *) {
        reverseGeocodeCoordinate(position.target)
    } else {
        // Fallback on earlier versions
    }
  }
}
swift xcode google-maps layout
1个回答
2
投票

改变你的设置方法

func setUpGoogleMap(){


            let camera = GMSCameraPosition.camera(withLatitude: 15.592778, longitude: 32.552278, zoom: 12)
        mapView = GMSMapView.map(withFrame: self.view.bounds, camera: camera)
        view .addSubview( mapView)
            mapView.animate(to: camera)
            mapView.isMyLocationEnabled = true
            locationManager.delegate = self
            locationManager.requestWhenInUseAuthorization()
            mapView.delegate = self
    //        mapView.translatesAutoresizingMaskIntoConstraints = false
        self.view.addSubview(locationBtn)
        self.view.addSubview(locationView)

        }
© www.soinside.com 2019 - 2024. All rights reserved.