将Google地图设置为视图

mazenqp

完成Google地图的设置后,我添加了三个子视图UIButton,可单击,我认为它可以正常工作,并且UIView和UIView顶部已将UITextField添加为(Subview),但我无法使用它,我无法输入任何它是不可编辑的,所以当我评论谷歌地图代码时,一切正常,但是我在UIView中允许textField正常工作

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
    }
  }
}
贾瓦德·阿里

更改您的设置方法

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)

        }

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Ammap.js 4-将地图设置为半静态视图球体+将mapObject设置为中心

来自分类Dev

如何使用 Angular2-Google-Maps 将 Google 地图设置为 2d

来自分类Dev

将谷歌地图设置为当前位置

来自分类Dev

无法让我的 Google 地图 supportMapFragment 将布局宽度/高度设置为“match_parent”

来自分类Dev

将表格视图设置为编辑模式

来自分类Dev

将图像视图背景设置为位图

来自分类Dev

从意图将图像设置为列表视图

来自分类Dev

将onClickListeners设置为很多视图

来自分类Dev

将图像视图背景设置为位图

来自分类Dev

将边距设置为“独立”视图

来自分类Dev

将imageview设置为水平滚动视图

来自分类Dev

将片段设置为列表视图的空视图

来自分类Dev

Google地图坐标视图

来自分类Dev

如何将地图缩放设置设置为20-Skobbler地图

来自分类Dev

无法将Google地图加载到网络视图中

来自分类Dev

将传单地图设置为高度:容器的100%

来自分类Dev

如何将数据设置为 firebase 地图对象

来自分类Dev

地图视图显示为白色

来自分类Dev

用于更新地图的 REST API 是否应该允许将地图设置为空?

来自分类Dev

如何将视图高度设置为等于其宽度

来自分类Dev

如何将列表视图设置为全角?

来自分类Dev

如何将图像的宽度设置为列表视图的宽度

来自分类Dev

如何将控制台设置为默认视图

来自分类Dev

如何从URL Android将图像设置为图像视图

来自分类Dev

将位图设置为文本视图的背景-Android

来自分类Dev

CakePHP将XML视图编码设置为UCS2

来自分类Dev

将CFileDialog的默认视图设置为大图标

来自分类Dev

将视图模型的属性设置为淘汰值

来自分类Dev

如何将静态UITableView设置为UIView的子视图?

Related 相关文章

热门标签

归档