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

Google Maps SDK iOS change floor level programmatically


I dont find any way in the documentation how to change the floor level programmatically. For example:

I load a specific polygon for 1 room, and i want to change the floor map to the specific floor level (For example Zoom to Level 2, and then add my Polygon).

Polygon adding with Infoboxes are not the problem, ill just want to know if its possible to programmatically select the right floor level.

Like here:

enter image description here

I still know that there is the GMSIndoorDisplayDelegate - and i am able to set the active building. There should be an "activeLevel" method, but i am unable to assign any value.


Solution

  • I found the solution on how to force the floor change for a particular building.

    1. Add the delegate GMSIndoorDisplayDelegate to the class,
    2. Set the delegates:

      mapView.delegate = self
      mapView.indoorDisplay.delegate = self
      
    3. Add the delegate methods:

      func didChangeActiveBuilding(building: GMSIndoorBuilding!) {
          if let currentBuilding = building {
              var levels = currentBuilding.levels as! [GMSIndoorLevel]
              mapView.indoorDisplay.activeLevel = levels[2] // set the level (key) 
          } 
      }
      
      func didChangeActiveLevel(level: GMSIndoorLevel!) { 
         println("will be called after activeBuilding")
      }
      

    P.S. Just a friendly reminder, the upmost level is the first item in the array. It's backwards.