First of all: I know there are similar threads here on So, but nothing thats suggested works for me.
Here is what i am trying to do: I want to have a PositionController(Class) that controls the users current position and gives interfaces for other classes,ViewControllers etc to use the information.
Currently i have this code implemented:
import Foundation
import CoreLocation
class PositionController: CLLocationManager, CLLocationManagerDelegate{
let locationManager: CLLocationManager
override init() {
self.locationManager = CLLocationManager()
print("---------------Init---------------------------")
}
func getPosition(){
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer
locationManager.requestLocation()
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print(error)
}
func locationManager(_ mnager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print(locations)
}
}
Note that the print statements in the delegate functions are only placeholders at the moment. Also note that i want the getPosition-Method to be called from outside ViewControllers. But when i call the function it just goes through the codeblock without calling neither of the two delegate functions at the end.
Further i have "Privacy - Location When In Use Description" and "Location Usage Description" added to my plist. I really dont know what i am missing or doing wrong, so all help is appreciated
EDIT:
import UIKit
import GoogleMaps
import GoogleMaps
class MapViewController: UIViewController, CLLocationManagerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// For use in foreground
print("-----------------------In------------------------")
let positionController = PositionController()
positionController.getPosition()
print("-----------------------Out------------------------")
let camera = GMSCameraPosition.camera(withLatitude: 48.137154
longitude: 11.576124, zoom:12)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera:camera)
let marker = GMSMarker()
marker.position = camera.target
marker.snippet = "Munich"
marker.appearAnimation = GMSMarkerAnimation.pop
marker.map = mapView
self.view = mapView
}