Basic map
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.
activity_sample_basic_map.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent">
<com.trimblemaps.mapsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
SampleBasicMapActivity.java
public class SampleBasicMapActivity extends AppCompatActivity {
private MapView mapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Authorize the api key for the session.
// .apiKey() requires your Trimble Maps API key
TrimbleMapsAccount trimbleMapsAccount = TrimbleMapsAccount.builder()
.apiKey(getString(R.string.API_KEY))
.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(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull TrimbleMapsMap trimbleMapsMap) {
// The TrimbleMapsMap object is created, now a style can be applied to render a map.
trimbleMapsMap.setStyle(Style.MOBILE_DAY, new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {
// The style is loaded, you can add content to the map, move it etc.
}
});
}
});
}
}