Search code examples
iosswiftxcodegoogle-mapsgoogle-maps-sdk-ios

Google Maps API for iOS - Marker is not displayed


I'm new to coding for iOS and I wanted to have a Map with a path/way on it in my Swift App. After trying to apply an KML Overlay, which didn't work, I decided to use a polyline. But the polyline wasn't desplayed either, so I tried a Marker, exactly following the tutorial at https://developers.google.com/maps/documentation/ios-sdk/marker, but the marker is also not displayed. What am I doing wrong? Here is my code for the Marker:

import UIKit
import GoogleMaps

class MapViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad() 

        GMSServices.provideAPIKey("MY_KEY")

        let camera = GMSCameraPosition.camera(withLatitude: 48.194857, longitude: 13.955710, zoom: 17)
        let mapView = GMSMapView.map(withFrame: .zero, camera: camera)
        mapView.mapType = .satellite
        mapView.setMinZoom(17, maxZoom: 19)
        view = mapView


        let marker = GMSMarker()
        marker.position = CLLocationCoordinate2D(latitude: 13.9553836,longitude: 48.1956954)
        marker.title = "Hello World"
        marker.map = mapView 

        // Do any additional setup after loading the view.
    }

}

Thank you in advance!


Solution

  • I think the code is okay, but the marker is not visible because it is in another part of the world. Try to exchange latitude and longitude of your marker marker.position = CLLocationCoordinate2D(latitude: 13.9553836,longitude: 48.1956954)

    Or set a lower zoom to your map