4

I'm trying to use Google Maps SDK to display a map of my current location (Berkeley, CA) as the focus, but regardless of what lat/lon I put in, it always shows Europe, as shown below:

enter image description here

Here is the code for the map view:

    let camera = GMSCameraPosition.cameraWithLatitude(37.8750360, longitude: -122.2573240, zoom: 1)
    mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
    mapView.myLocationEnabled = true
    mapView.delegate = self

I'm doing very similar things in other parts of my application, but have never gotten an issue. If someone knows how to fix this, please let me know! Thanks

Sampath Duddu
  • 277
  • 1
  • 5
  • 14

4 Answers4

0

Please make sure that you are test on real device. not be Simulator, If you use Simulator than enter latitude and longitude manually.

Like this-

enter image description here

Swift Developer
  • 247
  • 2
  • 18
0

You can test is on simulator as well and you can change location without enter lat-long for that you need to change location from your Xcode (above console Please rifler the below screen shot

enter image description here)

Community
  • 1
  • 1
Devil
  • 314
  • 3
  • 13
0

Maybe this is because you are setting the mapView's frame to CGRectZero. This may cause the map to have zero height and zero width.

Example based from this tutorial:

override func viewDidLoad()
{
let camera: GMSCameraPosition = GMSCameraPosition.cameraWithLatitude(37.8750360, longitude: -122.2573240, zoom: 1)
mapView = GMSMapView.mapWithFrame(self.view.frame, camera: camera)
mapView.camera = camera
}

Check these related questions:

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59
0

You're setting up your view before even setting your delegate (so your code isn't even attached to your instance of mapView). Fix it like this:

1: Make sure you've defined your GMSMapViewDelegate for the class

2: Set your delegates first

mapView.delegate = self
mapView.myLocationEnabled = true
let camera = GMSCameraPosition.cameraWithLatitude(37.8750360, longitude: -122.2573240, zoom: 1)
mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
Julian Lee
  • 293
  • 1
  • 11