Search code examples
swiftgoogle-places-apigoogle-maps-sdk-ios

No business POIs shown on GMSMapView, didTapPOIWithPlaceID not called


I'm showing a GMSMapView, but can't achieve to have business places like restaurants, hotels, shops, etc shown. According to the docs using the mapType kGMSTypeNormal should provide that request.

In addition, business POIs appear by default on the map when the map type is kGMSTypeNormal

Unfortunately, it only shows "official" POIs like parks, sights, hospitals and alike.

Furthermore I would have expected that the GMSMapViewDelegate member function mapView:didTapPOIWithPlaceID:name:location: is called when I tap one of these "official" POIs, but no matter where I tap, I don't get the function to be called. I temporarily tried the corresponding mapView:didTapAtCoordinate: just to make sure I set up the delegate correctly and this works perfectly.

Here is my code:

import UIKit
import GoogleMaps

class PoiGoogleMapVC: UIViewController, UITextFieldDelegate, CLLocationManagerDelegate, GMSMapViewDelegate {

    @IBOutlet weak var mainMap: GMSMapView!

    let locationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()
        mainMap.delegate = self
        locationManager.delegate = self

        let camera: GMSCameraPosition = GMSCameraPosition.camera(withLatitude: 48.857165, longitude: 2.354613, zoom: 8.0)
        self.mainMap.mapType = kGMSTypeNormal
        self.mainMap.camera = camera
        locationManager.requestWhenInUseAuthorization()
    }

    func mapView(_ mapView: GMSMapView, didTapPOIWithPlaceID placeID: String, name: String, location: CLLocationCoordinate2D) {
        print("You tapped \(name): \(placeID), \(location.latitude)/\(location.longitude)")
    }
}

What might be a hint to the solution, but at this point only confuses me, is that according to the api doc GMSMapView has a property called mapStyle. When I try to access this property Xcode gives me a compiler error:

Value of type 'GMSMapView' has no member 'mapStyle'


Solution

  • The mapStyle and business POIs were added in version 2.1, released on 22 September 2016. See here:

    https://developers.google.com/maps/documentation/ios-sdk/releases#version_21_-_september_22_2016

    Maybe you have an older version of the SDK?