Add a map to your application. Right out of the box, the map displays geographic boundaries, street names, road data, and more. The map can be then be styled, moved, and rotated.
importandroid.os.Bundle;importandroidx.annotation.NonNull;importandroidx.appcompat.app.AppCompatActivity;importcom.trimblemaps.account.LicensedFeature;importcom.trimblemaps.account.TrimbleMapsAccountManager;importcom.trimblemaps.account.models.TrimbleMapsAccount;importcom.trimblemaps.mapsdk.TrimbleMaps;importcom.trimblemaps.mapsdk.maps.MapView;importcom.trimblemaps.mapsdk.maps.OnMapReadyCallback;importcom.trimblemaps.mapsdk.maps.Style;importcom.trimblemaps.mapsdk.maps.TrimbleMapsMap;publicclassSampleBasicMapActivityextendsAppCompatActivity{privateMapViewmapView;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);// Authorize the API key for the session.// .apiKey() requires your Trimble Maps API keyTrimbleMapsAccounttrimbleMapsAccount=TrimbleMapsAccount.builder().apiKey("Your-API-key-here").addLicensedFeature(LicensedFeature.MAPS_SDK).build();// Initialize the sessionTrimbleMapsAccountManager.initialize(trimbleMapsAccount);TrimbleMapsAccountManager.awaitInitialization();// Get an instance of the map, done before the layout is set.TrimbleMaps.getInstance(this);setContentView(R.layout.activity_sample_basic_map);// Set up the MapView from the layoutmapView=findViewById(R.id.mapView);// the onMapReadyCallback is fired when the map is ready to be worked withmapView.getMapAsync(newOnMapReadyCallback(){@OverridepublicvoidonMapReady(@NonNullTrimbleMapsMaptrimbleMapsMap){// The TrimbleMapsMap object is created, now a style can be applied to render a map.trimbleMapsMap.setStyle(Style.MOBILE_DAY,newStyle.OnStyleLoaded(){@OverridepublicvoidonStyleLoaded(@NonNullStylestyle){// The style is loaded, you can add content to the map, move it etc.}});}});}/**
* Activity Overrides
*/@OverridepublicvoidonLowMemory(){super.onLowMemory();mapView.onLowMemory();}@OverridepublicvoidonStart(){super.onStart();mapView.onStart();}@OverridepublicvoidonResume(){super.onResume();mapView.onResume();}@OverridepublicvoidonStop(){super.onStop();mapView.onStop();}@OverridepublicvoidonPause(){super.onPause();mapView.onPause();}@OverridepublicvoidonDestroy(){super.onDestroy();mapView.onDestroy();}}
importandroid.os.Bundleimportandroidx.appcompat.app.AppCompatActivityimportcom.trimblemaps.account.LicensedFeatureimportcom.trimblemaps.account.TrimbleMapsAccountManagerimportcom.trimblemaps.account.models.TrimbleMapsAccountimportcom.trimblemaps.mapsdk.TrimbleMapsimportcom.trimblemaps.mapsdk.maps.MapViewimportcom.trimblemaps.mapsdk.maps.OnMapReadyCallbackimportcom.trimblemaps.mapsdk.maps.StyleclassSampleBasicMapActivity:Activity(){privatevarmapView:MapView?=nulloverridefunonCreate(savedInstanceState:Bundle?){super.onCreate(savedInstanceState)// Authorize the API key for the session.
// .apiKey() requires your Trimble Maps API key
valtrimbleMapsAccount=TrimbleMapsAccount.builder().apiKey("Your-API-key-here").addLicensedFeature(LicensedFeature.MAPS_SDK).build()// Initialize the session
TrimbleMapsAccountManager.initialize(trimbleMapsAccount)TrimbleMapsAccountManager.awaitInitialization()// Get an instance of the map, done before the layout is set.
TrimbleMaps.getInstance(this)setContentView(R.layout.activity_sample_basic_map)// Set up the MapView from the layout
mapView=findViewById(R.id.mapView)// the onMapReadyCallback is fired when the map is ready to be worked with
mapView?.getMapAsync(OnMapReadyCallback{trimbleMapsMap->// The TrimbleMapsMap object is created, now a style can be applied to render a map.
trimbleMapsMap.setStyle(Style.MOBILE_DAY){// The style is loaded, you can add content to the map, move it etc.
}})}/**
* Activity Overrides
*/overridefunonStart(){super.onStart()mapView?.onStart()}overridefunonResume(){super.onResume()mapView?.onResume()}overridefunonPause(){super.onPause()mapView?.onPause()}overridefunonStop(){super.onStop()mapView?.onStop()}overridefunonLowMemory(){super.onLowMemory()mapView?.onLowMemory()}overridefunonDestroy(){super.onDestroy()mapView?.onDestroy()}}