1

So I am trying to get it so I open the app and it starts off at the user's location. The problem is I am getting "User's location is unknown" in the output box. I have location enabled as seen in the code below, so I am wondering if something else might be causing this issue. Help would be appreciated thanks.

import UIKit
import GoogleMaps

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        let camera = GMSCameraPosition.cameraWithLatitude(-33.86,
                                                          longitude: 151.20, zoom: 6)
        let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
        mapView.accessibilityElementsHidden = false
        mapView.myLocationEnabled = true
        self.view = mapView

        if let mylocation = mapView.myLocation {
            print("User's location: \(mylocation)")
        } else {
            print("User's location is unknown")
        }
        let marker = GMSMarker()
        marker.position = CLLocationCoordinate2DMake(-33.86, 151.20)
        marker.title = "Sydney"
        marker.snippet = "Australia"
        marker.map = mapView

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}
Raktim Biswas
  • 4,011
  • 5
  • 27
  • 32
deee_geee
  • 15
  • 1
  • 3
  • Short answer - you can't directly. http://stackoverflow.com/questions/20967496/google-maps-ios-sdk-getting-current-location-of-user you'll need to query the location manager directly. – Warren Burton May 15 '16 at 21:22

2 Answers2

0

Have you tried using CLLocationManager() ?

Try the tutorial below, this should show you how to get the user's location. This will take you through asking the user for permission to see their location, down to reverse geocoding the location to display the address they are at, using GMSGeocoder()

[https://www.raywenderlich.com/109888/google-maps-ios-sdk-tutorial][1]

[1]: Ray Wenderlich

Hope that helps

Rowan Stanley
  • 122
  • 13
0

I tried this so:

  1. Set a custom String for the authorization request when in use (or whatever you need) in "Privacy - Location When In Use Usage Description" (or simply NSLocationWhenInUseUsageDescription) of my Info.plist properties file. Then this will ask you authorize finding your location.

  2. Set the properly delegate (GMSMapViewDelegate) in your view: for example

    class MapView: UIViewController, GMSMapViewDelegate{...}

  3. And finally set delegate to your GMSMapView instance. In my case mapView:

let mapView = GMSMapView.map(withFrame: frameMapViewContainer, camera: camera) mapView.delegate = self

Maxime
  • 1,332
  • 1
  • 15
  • 43