Skip to content

Nextome map integration

If you want, there’s an optional module that can show a live map of the indoor location of the user. You have two options to integrate the UI component:

  1. Integrate the PhoenixMapUtils (Recommended method), which is a wrapper that allows you to integrate easily the SDK with the Map module
  2. Integrate directly the NextomeMap. This method requires more boilerplate code but allows more customization

Integrate PhoenixMapUtils

In this sections we will go through the integration of the PhoenixMapUtils. If you're interested in th NextomeMap approach you can refer to this documentation.

Install the dependency

  1. In your build.gradle file, add dependencies for Nextome MapView and PhoenixMapUtils:
        implementation("com.nextome.phoenix_map_utils:phoenix_map_utils:1.4.3.3")
        implementation("net.nextome.nextome_map_module:flutter:1.5.1")
    
  1. Follow the How to include steps
  2. Update the Podfile adding the CocoaPods source and the Nextome source, the pod dependency and the post install script. You don't need to specify the Phoenix sdk because it is already defined as PhoenixMapUtils dependency.

    platform :ios, '13.2'
    
    source 'https://github.com/CocoaPods/Specs.git'
    source 'https://github.com/Nextome/Specs'
    
    use_frameworks!
    
    target 'MyApp' do
        pod 'PhoenixMapUtils_Release', '1.4.4.1'
    end
    
    post_install do |installer|
        installer.generated_projects.each do |project|
            project.targets.each do |target|
                target.build_configurations.each do |config|
                    config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.2'
                end
            end
        end
    end
    

    Note

    The PhoenixMapUtils is distributed in two different pod version, Release and Debug. Th release version will compile also for the simulate but will not show the map view. To test the map on the simulator you can use the Debug version instead. It is important to use the Release version for the app store.

  3. Install the dependency

    pod install
    

Initialization

The first step is to initialize the module.

  1. In your .xml layout, add a PhoenixMapView where you want to display the indoor map.
        <com.nextome.phoenix_map_utils.PhoenixMapView
            android:id="@+id/indoor_map"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
  2. In your Activity/ViewModel, initialize PhoenixMapHandler
        val handler = PhoenixMapHandler()
    
        val fragmentManager: FragmentManager = supportFragmentManager
        handler.initialize(
            fragmentManager = fragmentManager,
            viewId = R.id.indoor_map, // View created before
            context = this
        )
    
  1. Open th AppDelegate
  2. Import the module
        import PhoenixMapUtils
    
  3. Initialize the PhoenixMapHandler in the didFinishLaunchingWithOptions method:
        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
            // Override point for customization after application launch.
            PhoenixMapHandler.instance.initialize()
            return true
        } 
    
    The PhoenixMapHandler provide a UIViewController/Fragment and some methods to handle it.

Integration

  1. Import the module
        import PhoenixMapUtils
    
  2. Initialize the Fragment/UIViewController The PhoenixMapHandler provides a UIViewController that you can use to show the flutter map.
    lazy var indoorMapViewController: UIViewController = PhoenixMapHandler.instance.initializeFlutterViewController()

Show a new indoor map

Once a map is available, pass the tiles local directory, height and width of the map to the PhoenixMapHandler. Those parameters can be obtained from the LocalizationRunningState during localization or from the specific map returned in the NextomeVenueData. More info on the venue data can be retrieve here.

handler.setMap(mapTilesUrl = mapTilesUrl, mapHeight = mapHeight, mapWidth = mapWidth)

PhoenixMapHandler.instance.setMap(tilesZipPath: runningState.tilesZipPath,
                                    mapHeight: runningState.mapHeight,
                                    mapWidth: runningState.mapWidth)

Update user live position

When a new indoor user position is available, notify PhoenixMapHandler to update the blue point with:

    viewModel.nextomeSdk.getLocalizationObservable().asLiveData().observe(this) {
        handler.updatePositionOnMap(it)
    }    
    func observeSdkLocations(){
    let watcher = nextomeSdk.getLocalizationObservable().watch(block: {position in
        if let position = position{
            self.lastPosition = position
            PhoenixMapHandler.instance.updatePositionOnMap(position)
        }
    })

    watchers.append(watcher)
    }   

Show a list of Point of Interest

You can set the list of Point of Interest to show on the map using this method:

handler.updatePoiList(pois)
let pois: [NextomePoi] = runningState.venueData.getPoisByMapId(mapId: runningState.mapId)
PhoenixMapHandler.instance.updatePoiList(pois)

Show a path between two points on map

You can show a path on the map using this method and passing a list of Vertex. You can automatically get the Vertext between a start and end point of the map using the appropriate method on the nextomeSdk:

hanlder.updatePath(path)
func showPath(path: [Vertex]){
    PhoenixMapHandler.instance.updatePath(path: path)
}

Observe events on Flutter Map

With this observer you can be notified of events on the map, for example, when the user decides to navigate to a POI.

handler.observeEvents().collect { event ->
    when (event) { 
        is PhoenixMapHandler.OnNavigationSelected -> {
            // user clicked on "Navigate to POI"
            val poi = event.poi
        } 
        is PhoenixMapHandler.OnPoiClicked -> { 
            // user clicked on poi 
            val poi = event.poi 
        }
    } 
}
  1. Extend the NextomeMapDelegate

    class MapViewController: UIViewController, NextomeMapDelegate {
    
    }
    
  2. Implement the onPoiClicked method to be notified when the user clicked on a POI.

    func onPoiClicked(poi: NextomePoi){
    
    }
    
  3. Implement the onNavigationSelected method to be notified when the user wants to navigate to a POI.

    func onPoiClicked(poi: NextomePoi){
    
    }
    

Show Center Position Fab

It’s possible to show an optional fab at the bottom right of the map. When clicked, the button will:

  • center the map on the user position;
  • follow the user position live on map;
  • rotate the map based on user compass;

To enable the button, use:

handler.setMapViewSettings(fabEnabled = true)

  1. Extend the NextomeMapDelegate

    class MapViewController: UIViewController, NextomeMapDelegate {
    
    }
    
  2. Implement the onPoiClicked method to be notified when the user want to navigate to a certain POI.

    PhoenixMapHandler.instance.setMapSettings(fabEnabled: true)
    

Change user position icon

The default position icon is a blue dot. If you want to change the icon, you can load a remote resource from an url.

handler.setMapViewSettings(customPositionResourceUrl = "url")

Note

The compass feature will only work if the app has the following permissions:

android.permission.INTERNET
android.permission.ACCESS_COARSE_LOCATION
android.permission.ACCESS_FINE_LOCATION
If those permissions are not denied, the navigation button will only follow user position without rotating.

  1. Extend the NextomeMapDelegate

    class MapViewController: UIViewController, NextomeMapDelegate {
    
    }
    
  2. Implement the onPoiClicked method to be notified when the user want to navigate to a certain POI.

    let remotePath = ""http://nextome.com/position-icon.png""
    PhoenixMapHandler.instance.setMapSettings(customPositionResourceUrl: remotePath)
    

React to activity lifecycle (Android Only)

PhoenixMapUtils 1.4.3.3

On Android, we suggest to foward to PhoenixMapUtils all the methods releated to the management of the activity lifecycle. This will allow to save and recover the state of the map if configuration changes happens (for example, when the user rotates the phone screen).

To do so, override the following methods in your activity:

    fun onPostResume() {
        super.onPostResume()
        handler.onPostResume()
    }

    fun onNewIntent(intent: Intent) {
        handler.onNewIntent(intent)
    }

    fun onBackPressed() {
        handler.onBackPressed()
    }

    fun onRequestPermissionsResult(
        requestCode: Int,
        permissions: Array<out String>,
        grantResults: IntArray
    ) {
        handler.onRequestPermissionsResult(
            requestCode,
            permissions,
            grantResults
        )
    }

    fun onActivityResult(
        requestCode: Int,
        resultCode: Int,
        data: Intent?
    ) {
        super.onActivityResult(requestCode, resultCode, data)
        handler.onActivityResult(
            requestCode,
            resultCode,
            data
        )
    }

    fun onUserLeaveHint() {
        handler.onUserLeaveHint()
    }

    fun onTrimMemory(level: Int) {
        super.onTrimMemory(level)
        handler.onTrimMemory(level)
    }

Additionally, you must add this line in AndroidManifest.xml to all the activities that use NextomeMap:

    <activity
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
        ...