代码之家  ›  专栏  ›  技术社区  ›  Ussaid Iqbal

谷歌地图奇怪的行为斯威夫特4 ios

  •  1
  • Ussaid Iqbal  · 技术社区  · 8 年前

    更新 :它和语言有什么关系吗?因为我的应用程序是体育英语和阿拉伯语。

    working maps

    然后当我拔下设备,重新打开应用程序它停止工作,应用程序运行良好,但我看不到任何地图,但只是像下面的屏幕截图标记。 not working map

    任何帮助都将不胜感激。

    应用程序委派

     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        GMSServices.provideAPIKey(googleApiKey)
        GMSPlacesClient.provideAPIKey(googleApiKey)       
        return true
    
    }
    

    视图控制器

         //Step 1
         @IBOutlet weak var mapview: GMSMapView!
    
          //Step 2
         override func viewDidAppear(_ animated: Bool) {
                super.viewDidAppear(animated)
                self.mapview.settings.scrollGestures = true
                self.mapview.settings.zoomGestures = true
                self.mapview.isMyLocationEnabled = true
                self.mapview.settings.myLocationButton = true
                self.mapview.delegate = self
                self.mapview.layoutIfNeeded()
    
            }
    
        }
    
        //Step 3 After we have the current location items are loaded from server by user location and the markers are added in GetBusinesses function
        extension ItemsList: CLLocationManagerDelegate {
            func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
                guard status == .authorizedWhenInUse else {
                    return
                }
                    self.locationManager.startUpdatingLocation()
    
                    self.mapview.camera = GMSCameraPosition(target:  (self.locationManager.location?.coordinate)!, zoom: 14, bearing: 0, viewingAngle: 0)
                    self.GetBusinesses(data: "&isOpen=2&cat=\(Prefrences.getSelectedCategoryId())")
            }
        }
    
    2 回复  |  直到 8 年前
        1
  •  2
  •   Mohmmad S    8 年前

    要在自定义视图中显示地图,必须这样做,

     let camera = GMSCameraPosition.camera(withLatitude: lat , longitude: long, zoom: 15.0)
        let mapView = GMSMapView.map(withFrame: CGRect(x: 2, y: 2, width: self.MapView.frame.width - 4, height: self.MapView.frame.height - 2), camera: camera)
        self.MapView.addSubview(mapView)
        self.MapView.clipsToBounds = true
        self.MapView.contentMode = .center
    

    您需要使用在序列图像板框架上创建的地图视图创建地图视图,并将其作为子视图添加到您创建的主地图视图中

        2
  •  2
  •   Ussaid Iqbal    8 年前

    好吧,在挣扎了很多天,尝试了所有愚蠢的方法来修复它之后,我终于找到了解决方法。主要的问题是,如果你的应用程序支持多种语言,那么谷歌地图将显示这种行为。下面是修复它的步骤。

    第一步: 打开插座 因为它将被创建 动态 .

    第二步: 根据用户设置设置应用程序语言。

    创建自定义GMSMapView对象集委托方法和其他必要的设置,并将其添加到其容器中。

    就这样,你可以走了。我从中了解到,在创建GMSMapView之前,必须先设置应用程序语言(

        //Our Custom MapView Var
        var mapview: GMSMapView!
    
    
        //View viewDidLoad() function
        override func viewDidLoad() {
                super.viewDidLoad()
                /*
                  TODO: 
                  Get selected language from preferences and set accordingly. 
                */
                UserDefaults.standard.set(["en"], forKey: "AppleLanguages")
                UserDefaults.standard.synchronize()
    
                let camera = GMSCameraPosition.camera(withLatitude: 55.277397,
                                                      longitude: 25.199514,
                                                      zoom:12)
                self.mapview = GMSMapView.map(withFrame: self.mMapContainer.bounds, camera: camera)
                self.mapview.delegate = self
                self.mapview.isMyLocationEnabled = true
                self.mapview.settings.myLocationButton = true
                self.mapview.isMyLocationEnabled = true
                self.mapview.autoresizingMask = [.flexibleWidth, .flexibleHeight]
                mMapContainer.addSubview(self.mapview)
    }
    
    推荐文章