Location Details

Last updated:

This is an example of displaying some details of a MapsIndoors location

Start by creating a Fragment or an Activity class that contains the Google map fragment:

public class LocationDetailsFragment extends Fragment
//
{

Add a GoogleMap and a MapControl to the class:

MapControl mMapControl;
GoogleMap mGoogleMap;

Add other needed views for this example:

SupportMapFragment mMapFragment;
TextView detailsTextView;

The Venue's coordinates:

static final LatLng VENUE_LAT_LNG = new LatLng( 57.05813067, 9.95058065 );

Setup the needed views for this example:

private void setupView( View rootView )
{
final FragmentManager fm = getChildFragmentManager();
detailsTextView = rootView.findViewById( R.id.details_text_view );
mMapFragment = (SupportMapFragment) fm.findFragmentById( R.id.mapfragment );
mMapFragment.getMapAsync( mOnMapReadyCallback );
}

Once the map is ready move the camera to the venue location and call the setupMapsIndoors:

OnMapReadyCallback mOnMapReadyCallback = new OnMapReadyCallback() {
@Override
public void onMapReady( GoogleMap googleMap )
{
mGoogleMap = googleMap;
mGoogleMap.moveCamera( CameraUpdateFactory.newLatLngZoom( VENUE_LAT_LNG, 13.0f ) );
setupMapsIndoors();
}
};

Setup MapsIndoors:

void setupMapsIndoors()
{
final Activity context = getActivity();
if( (context == null) || (mMapFragment == null) || (mMapFragment.getView() == null) )
{
return;
}

Setting the API key to the desired Solution. Needed here as we are switching Solutions:

if( !MapsIndoors.getAPIKey().equalsIgnoreCase( getString( R.string.mi_api_key ) ) )
{
MapsIndoors.setAPIKey( getString( R.string.mi_api_key ) );
}

Setting the Google API key:

MapsIndoors.setGoogleAPIKey( getString( R.string.google_maps_key ) );

Instantiate and init the MapControl object which will sync data:

mMapControl = new MapControl( context );
mMapControl.setGoogleMap( mGoogleMap, mMapFragment.getView() );

When a marker is clicked, get the related MapsIndoors location object and set the label text based on the name and description of the location:

mMapControl.setOnMarkerClickListener( marker -> {
final MPLocation loc = mMapControl.getLocation( marker );
if( loc != null )
{
marker.showInfoWindow();
if( detailsTextView.getVisibility() != View.VISIBLE )
{

Show the Name and the description of a POI in a label:

detailsTextView.setText( "Name: " + loc.getName() + "\nDescription: " + loc.getDescription() );
detailsTextView.setVisibility( View.VISIBLE );
rue;
setOnMarkerInfoWindowCloseListener( marker -> {
ilsTextView.getVisibility() == View.VISIBLE )
ilsTextView.setVisibility( View.INVISIBLE );

Init the MapControl object which will sync data:

mMapControl.init( miError -> {
if( miError == null )
{

Select a floor and animate the camera to the venue position:

mMapControl.selectFloor( 1 );
mGoogleMap.animateCamera( CameraUpdateFactory.newLatLngZoom( VENUE_LAT_LNG, 20f ) );

See the sample in LocationDetailsFragment.java

  1. Developing on the new Arm-based Apple Silicon (M1) Macs requires building and running on a physical iOS device or using an iOS simulator running iOS 13.7, e.g. iPhone 11. This is a temporary limitation in Google Maps SDK for iOS, and as such also a limitation in MapsIndoors, due to the dependency to Google Maps.
  2. Note: Due to a bug in CocoaPods it is necessary to include the post_install hook in your Podfile described in the PodFile post_install wiki.

This is an example of displaying some details of a MapsIndoors location

Start by creating a UIViewController class that conforms to the GMSMapViewDelegate protocol

class LocationDetailsController: UIViewController, GMSMapViewDelegate {

Add a GMSMapView and a MPMapControl to the class

var map: GMSMapView? = nil
var mapControl: MPMapControl? = nil

Add other views needed for this example

var detailsView:UIStackView = UIStackView.init()
var mainView:UIStackView = UIStackView.init()
var nameLabel = UILabel.init()
var descrLabel = UILabel.init()

Inside viewDidLoad, setup the map and the mapControl instance:

self.map = GMSMapView.init(frame: CGRect.zero)
self.map?.delegate = self
self.map?.camera = .camera(withLatitude: 57.057964, longitude: 9.9504112, zoom: 20)
self.mapControl = MPMapControl.init(map: self.map!)

Setup the label views

nameLabel = UILabel.init()
descrLabel = UILabel.init()
nameLabel.backgroundColor = UIColor.white
descrLabel.backgroundColor = UIColor.white

Arrange the labels inside a stackview

detailsView = UIStackView.init(arrangedSubviews: [nameLabel, descrLabel])
detailsView.axis = .vertical

Arrange the map and the stackview inside another stackview

mainView = UIStackView.init(arrangedSubviews: [map!, detailsView])
mainView.axis = .vertical

When marker is tapped, get related MapsIndoors location object and set label text, based on the name and description of the location

func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
let location = mapControl?.getLocation(marker)
if location != nil {
self.nameLabel.text = location?.name
self.descrLabel.text = location?.descr
}
return false
}

When map is tapped, reset label text

func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
self.nameLabel.text = nil
self.descrLabel.text = nil
}

See the sample in LocationDetailsController.swift