2

When the view loads on initial launch(tap of icon/run program), the google Map View starts in the united kingdom then teleports to my current location in a very abrupt manner. Nowhere in my code do I have any UK Coordinates that I would think would cause it to load there then teleport to my location.

How can I solve this issue and make the launch process more elegant?

let locationManager = CLLocationManager()
let googleMapView: GMSMapView!

override func viewDidLoad() {
    super.viewDidLoad()

    self.locationManager.requestAlwaysAuthorization()
    self.locationManager.requestWhenInUseAuthorization()

    if CLLocationManager.locationServicesEnabled() {
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.startMonitoringSignificantLocationChanges()

    }

}

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)

    self.googleMapView = GMSMapView(frame: self.mapViewContainer.frame)
    self.view.addSubview(self.googleMapView)
    self.googleMapView.myLocationEnabled = true
    self.googleMapView.settings.compassButton = true

}

Beginning of Launch

Abruptly shifts to current location

lifewithelliott
  • 1,012
  • 2
  • 16
  • 35
  • Refer this one, It may help you. http://stackoverflow.com/questions/32043284/ios-google-maps-plotting-multiple-markers-issuesinfo-window-and-marker-repeatin/32043675#32043675 – VRAwesome Jan 25 '16 at 06:13
  • i appreciate it, but i don't have any issues with coordinates, and markers being repeated or placed in the wrong area. Simply for exampled, if you download the google maps app, as soon as you open up the app it zooms in perfectly at your current location. In my app, It arbitrarily begins hovered over the united kingdom and zooms in an unattractive manner to my current location – lifewithelliott Jan 25 '16 at 06:38
  • I meant to say that, follow basic procedure if you forget any of step, then you can check it out. Set `self.gMapView.myLocationEnabled = YES;` in `viewDidAppear()` where you have define `GMSMapView`. – VRAwesome Jan 25 '16 at 06:44
  • ah, i had that set in my didUpdateLocations method, but just changed it to be called in viewDidAppear. But nothing had changed, my initial view is still the UK and teleports me to my current location afterwords – lifewithelliott Jan 25 '16 at 06:58

2 Answers2

0

You may try using Map Objects. By default, no location data is shown on the map. You may enable the blue "My Location" dot and compass direction by setting myLocationEnabled on GMSMapView.

mapView.myLocationEnabled = true

By enabling this feature will also provide the user's current location through the myLocation property.

if let mylocation = mapView.myLocation {
  print("User's location: \(mylocation)")
} else {
  print("User's location is unknown")
}

This property may not be immediately available - for example, if the user is prompted by iOS to allow access to this data. It will be nil in this case.

abielita
  • 13,147
  • 2
  • 17
  • 59
  • interesting, I've tried manipulating it in some ways, but still the first location that appears is in the UK, – lifewithelliott Jan 26 '16 at 16:02
  • You can try [Geolocation](https://developers.google.com/maps/articles/geolocation) that refers to the identification of the geographic location of a user or computing device via a variety of data collection mechanisms. Typically, most geolocation services use network routing addresses or internal GPS devices to determine this location. This [guide](https://developers.google.com/maps/documentation/geolocation/intro) might help you. – abielita Jan 27 '16 at 04:08
  • I do wonder if i really need to implement geolocation as well. seems like it would be a bit more than I would have to do just to load my current location on the map as soon as the map appears. Calling the code you had implemented to print my location in the viewDidLoad - a fatal error, unexpectedly found nil - occurs and in the viewDidAppear an output "users location is unknown." Just wondering why it takes so long for the location to be tracked when the google maps app appears instantaneously – lifewithelliott Feb 02 '16 at 19:15
0

You have to initialize your map with camera (and location init). Example:

var map: GMSMapView!

init() {
map = GMSMapView(frame: view.frame, camera: GMSCameraPosition.camera(withTarget: getMyCoordinate(), zoom: mySavedZoom()))
}