Google Maps不显示/加载iOS

时间:2019-01-03 12:33:20

标签: ios google-maps ios12 swift4.2

我开始使用google maps,首先显示的是map,但是什么也没有显示,而日志中却显示

CoreData:注释:无法在路径'/ var / containers / Bundle / Application / EA2D4483-D98A-4D23-AFE4-ACDD86C0DF2A / Key Sensor.app/GoogleMaps.bundle/GMSCacheStorage.momd/ StorageWithTileProto.omo CoreData:注释:无法在路径'/ var / containers / Bundle / Application / EA2D4483-D98A-4D23-AFE4-ACDD86C0DF2A / Key Sensor.app/GoogleMaps.bundle/GMSCacheStorage.momd/StorageWithTileProto.omo'上加载优化的模型 CoreData:注释:无法在路径'/ var / containers / Bundle / Application / EA2D4483-D98A-4D23-AFE4-ACDD86C0DF2A / Key Sensor.app/GoogleMaps.bundle/GMSCacheStorage.momd/StorageWithTileProto.omo'加载优化模型strong>

我尝试过的事情

我在api console中限制了bundle id。 我还尝试了删除StorageWithTileProto.omo文件。 我多次清理了项目。 我多次重启电话。 我还创建了一个新项目,该项目显示相同的错误。

这是我的代码

import Foundation
import UIKit
import GoogleMaps

class GoogleMaps :UIViewController {

 var gsmMapView: GMSMapView!



@IBOutlet weak var mapView: UIView!

let loacationManager = CLLocationManager()

override func viewDidLoad() {

    navigationController?.navigationBar.barTintColor =  
  UIColor.hexStringToUIColor(hex: "#555555")

    loacationManager.delegate = self

    loacationManager.requestAlwaysAuthorization()




    // Zoom to location
    let camera = GMSCameraPosition.camera(withLatitude: 0,
                                          longitude: 0, zoom: 6.0)
    // get google Maps
    gsmMapView = GMSMapView.map(withFrame: CGRect.zero, camera: 
    camera)
    mapView.addSubview(gsmMapView)

    }

   func toast(message msg: String) 
   {self.navigationController?.view.makeToast(message: msg)}
    }


extension GoogleMaps : CLLocationManagerDelegate{

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

    print("status \(status.rawValue)")
    if(status != CLAuthorizationStatus.authorizedAlways){

        permissionDialog()
        return
    }
    loacationManager.startUpdatingLocation()





}

func locationManager(_ manager: CLLocationManager, didUpdateLocations 
 locations: [CLLocation]) {

    toast(message: "didUpdateLocations")
    guard let location = locations.first else {
        return
    }

    // 7
    //        gsmMapView.camera = GMSCameraPosition(target: 
           location.coordinate,
       //       zoom: 15, bearing: 0, viewingAngle: 0)
    //        
    // 8
    loacationManager.stopUpdatingLocation()
}

func locationManager(_ manager: CLLocationManager, 
  monitoringDidFailFor region: CLRegion?, withError error: Error) {
    print("Monitoring failed for region with identifier: \ . 
     (region!.identifier)")
 }

func locationManager(_ manager: CLLocationManager, didFailWithError 
 error: Error) {
    print("Location Manager failed with the following error: \ . 
 (error)")
}


func permissionDialog() {
    self.toast(message: "Give Always Authorization Premission")

    let alertController = UIAlertController(title: "Permission",
                                            message: "Please go to 
  Settings and turn on the location alway               permissions 
    for to work",
                                            preferredStyle: .alert)
    let settingsAction = UIAlertAction (title: "Settings", style: 
    .default, handler: ({ (_) -> Void in

        guard let settingsUrl = URL(string: 
 UIApplication.openSettingsURLString) else {
            return}
        if(UIApplication.shared.canOpenURL(settingsUrl)){
            UIApplication.shared.open(settingsUrl, options: [:], completionHandler: { (success) in })

        }
    }))
    let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, 
  handler: nil)

    alertController.addAction(settingsAction)
    alertController.addAction(cancelAction)
    self.present(alertController, animated: true, completion: nil)
}

}

我的快速版本是4.2,构建目标版本是12.1。请让我知道我是什么

1 个答案:

答案 0 :(得分:0)

尝试

gsmMapView = GMSMapView.map(withFrame: mapView.bounds, camera: camera)
mapView.addSubview(gsmMapView)