Программируем под IOS
Anonymous
Тема 1: Неустранимая ошибка: неожиданно обнаружено ноль при неявном развертывании необязательного значения — MapView.isM
Сообщение
Anonymous » 31 мар 2024, 03:07
gives the following error. How do I fix it?
Код: Выделить всё
import GoogleMaps
class ViewController: UIViewController,CLLocationManagerDelegate {
//Outlets
@IBOutlet var MapView: GMSMapView!
//Variables
var locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
initializeTheLocationManager()
self.MapView.isMyLocationEnabled = true
}
func initializeTheLocationManager() {
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
var location = locationManager.location?.coordinate
cameraMoveToLocation(toLocation: location)
}
func cameraMoveToLocation(toLocation: CLLocationCoordinate2D?) {
if toLocation != nil {
MapView.camera = GMSCameraPosition.camera(withTarget: toLocation!, zoom: 15)
}
}
}
Вот как выглядит раскадровка. Я новичок в Swift и хочу видеть свое текущее местоположение на Картах Google через Swift. Что мне следует сделать по-другому?
Подробнее здесь:
https://stackoverflow.com/questions/782 ... ing-an-opt
1711843673
Anonymous
[code]self.MapView.isMyLocationEnabled = true [/code] gives the following error. How do I fix it? [code]import GoogleMaps class ViewController: UIViewController,CLLocationManagerDelegate { //Outlets @IBOutlet var MapView: GMSMapView! //Variables var locationManager = CLLocationManager() override func viewDidLoad() { super.viewDidLoad() initializeTheLocationManager() self.MapView.isMyLocationEnabled = true } func initializeTheLocationManager() { locationManager.delegate = self locationManager.requestWhenInUseAuthorization() locationManager.startUpdatingLocation() } func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { var location = locationManager.location?.coordinate cameraMoveToLocation(toLocation: location) } func cameraMoveToLocation(toLocation: CLLocationCoordinate2D?) { if toLocation != nil { MapView.camera = GMSCameraPosition.camera(withTarget: toLocation!, zoom: 15) } } } [/code] Вот как выглядит раскадровка. Я новичок в Swift и хочу видеть свое текущее местоположение на Картах Google через Swift. Что мне следует сделать по-другому? [img]https://i.stack.imgur.com/XdqUF.png[/img] [img]https://i.stack.imgur.com/4y2FI.png[/img] Подробнее здесь: [url]https://stackoverflow.com/questions/78249756/thread-1-fatal-error-unexpectedly-found-nil-while-implicitly-unwrapping-an-opt[/url]