【发布时间】:2018-06-11 21:39:01
【问题描述】:
我正在尝试在 swift 上创建一个显示用户所在位置的视图控制器。我已经实现了谷歌地图,所以现在我要做的就是插入正确的代码。这样做时,我不断收到这两条错误消息,然后应用程序崩溃。有人可以帮我找出解决方案吗>感谢所有帮助。
import UIKit
import Foundation
import Firebase
import MapKit
import GoogleMaps
import CoreLocation
class mainViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
let defaults = UserDefaults.standard
let locationManager = CLLocationManager()
var mapView = GMSMapView()
var camera = GMSCameraPosition()
override func viewDidLoad() {
super.viewDidLoad()
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
GMSServices.provideAPIKey("AIzaSyBDOLisA3c-wDTbkbSssAxEb3iLw7Y5vHo")
let camera = GMSCameraPosition.camera(withLatitude: (self.locationManager.location?.coordinate.latitude)!, longitude: (self.locationManager.location?.coordinate.latitude)!, zoom: 17)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
view = mapView
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: (self.locationManager.location?.coordinate.latitude)!, longitude: (self.locationManager.location?.coordinate.latitude)!)
marker.snippet = "Current Location"
marker.map = mapView
self.mapView.addSubview(mapView)
view.backgroundColor = GREEN_Theme
navigationController?.navigationBar.prefersLargeTitles = true
navigationItem.title = "Welcome"
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Logout", style: .plain, target: self, action: #selector(Logout))
}
@objc func Logout() {
print("Logged Out")
do {
// I am receiving this error message on the auth.auth().signOut() "Use of unresolved identifier 'Auth'"
try Auth.auth().signOut()
defaults.set(false, forKey: "user is logged in")
let loginController = UINavigationController(rootViewController: LoginController())
present(loginController, animated: true, completion: nil)
} catch let err {
print(err.localizedDescription)
}
}
}
【问题讨论】:
-
抱歉,我在这里收到错误消息(让 camera = GMSCameraPosition.camera(withLatitude: (self.locationManager.location?.coordinate.latitude)!, longitude: (self.locationManager.location? .coordinate.latitude)!, zoom: 17) let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera) view = mapView) 消息说 Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) 请帮忙我解决这个问题!
-
你通过声明变量mapView创建了一个GMSMapView的实例,然后你又声明了一个mapView的常量?
-
@Do2 谢谢,你能解释一下如何解决这个问题吗?
-
@Do2 当我删除 let 时,我得到一个“使用未解析的标识符‘mapView’
-
你试过 self.mapView 吗?
标签: swift firebase firebase-authentication gmsmapview