谷歌地图加载问题iOS

问题描述 投票:-2回答:2

我已经在我的项目中使用pod集成了GoogleMap但是地图没有加载。当我将mapViewController作为初始ViewController时,它的工作正常。

但是当我推送或呈现MapViewController时,它会向我显示空白屏幕。

我正在使用XCode 9.1,我的项目部署目标是9.0Google Maps SDK for iOS version: 2.5.30219.0

提前致谢。

这是我的MapViewController代码:

import UIKit
import GoogleMaps

class MapViewController: UIViewController {

    @IBOutlet weak var mapView: GMSMapView!
    override func viewDidLoad() {
        super.viewDidLoad()

        let camera = GMSCameraPosition.camera(withTarget: CLLocationCoordinate2DMake(18.486726, 73.798394), zoom: 10)
        mapView.camera = camera
    }
}

控制台日志:

CoreData:注释:无法在路径中加载优化模型

/Users/pritamsing.salunkhe/Library/Developer/CoreSimulator/Devices/6DD7C0EA-320F-4E99-BEC9-672046198800/data/Containers/Bundle/Application/04CC747F-5B2D-4588-883A-E814D4EE0769/HimmatPlus.app/GoogleMaps.bundle/GMSCacheStorage.momd/StorageWithTileVersionID.omo

MapViewController when set as initial conrtroller

MapViewController when push from another ViewController

ios swift google-maps
2个回答
0
投票

不要在故事板中使用IBOutlet用于googleMap,也不要为GMSMapView设置子类。

通过编程实现您的地图。它将更快地提升你的Map UI

/// Google MapView
var mapView: GMSMapView!

self.mapView = GMSMapView(frame: CGRect(x: 0, y: 64, width: self.currentDeviceSize.width, height: self.bottomBgView.frame.minY - 64))
    // self.mapView.autoresizingMask = [.flexibleBottomMargin, .flexibleTopMargin, .flexibleLeftMargin, .flexibleRightMargin]
self.mapView.settings.allowScrollGesturesDuringRotateOrZoom = true
// self.mapView.settings.myLocationButton = true //Enable My location button
// self.mapView.isTrafficEnabled = true //Enable traffic
// self.mapView.isBuildingsEnabled = true // Building Enable
//  self.mapView.isMyLocationEnabled = true //My location Enabled

// let containerView: GMSMapView = self.mapView
self.view.addSubview(self.mapView)

0
投票

尝试正确实施Google地图。

@IBOutlet weak var mapView: GMSMapView!
var locationManager = CLLocationManager()

override func viewDidLoad() {
    super.viewDidLoad()
    mapView.delegate = self
    self.configureMap()
}

func configureMap(){
    mapView.delegate = self
    //Check for Location Services
    if (CLLocationManager.locationServicesEnabled()) {
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.distanceFilter = kCLDistanceFilterNone
        locationManager.requestWhenInUseAuthorization()
    }
    if CLLocationManager.locationServicesEnabled() {
        locationManager.startUpdatingLocation()
    }
} 

MapView Delegate方法

//MARK:- MapView delegate
extension YourViewControllerName: GMSMapViewDelegate,   CLLocationManagerDelegate{
    //Location Manager delegates
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

        let location = locations.last
        let camera = GMSCameraPosition.camera(withLatitude: (location?.coordinate.latitude)!, longitude: (location?.coordinate.longitude)!, zoom: 12.0)
        self.mapView?.animate(to: camera)
        // To stop updating the location again 
        self.locationManager.stopUpdatingLocation()
    }

    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
        print("error description:\(error.localizedDescription)")
    }

}

键入plist文件。

<key>NSLocationWhenInUseUsageDescription</key>
<string>Your custom message.</string>
© www.soinside.com 2019 - 2024. All rights reserved.