Simple MapView
This example shows how to display a simple map view in activity, this map view does not contain complicated functions, only basic UI.
For all code examples, refer to Android Maps SDK Code Examples
activity_simple_map_view.xml view source
SimpleMapViewActivity view source
Code summary
The SimpleMapViewActivity class extends the AppCompatActivity class and implements the OnMapReadyCallback interface. It can be used to display a map view in an Android app.
The class has the following members:
-
mapView: A MapView object that is used to display the map.
-
mMap: A NextbillionMap object that represents the map data.
The class overrides the following methods:
-
onCreate(): This method is called when the activity is first created. It initializes the map view and sets the map's style.
-
onMapReady(): This method is called when the map is ready to be used. It sets the map's center and zoom level.
-
onStart(): This method is called when the activity starts. It starts the map view.
-
onResume(): This method is called when the activity resumes. It resumes the map view.
-
onPause(): This method is called when the activity pauses. It pauses the map view.
-
onStop(): This method is called when the activity stops. It stops the map view.
-
onSaveInstanceState(): This method is called when the activity is saved to the state. It saves the map view's state.
-
onDestroy(): This method is called when the activity is destroyed. It destroys the map view.
-
onLowMemory(): This method is called when the device is low on memory. It reduces the map view's memory usage.
Here are some additional details about the code:
-
The onCreate() method initializes the map view and sets the map's style. The map view is initialized by calling the setContentView() method and passing it to the R.layout.activity_simple_map_view layout resource. The map's style is set by calling the mMap.getStyle() method and pass it to a listener that will be called when the style is loaded.
-
The onMapReady() method is called when the map is ready to be used. It sets the map's center and zoom level. The map's center is set by calling the mMap.setCenter() method and passing it the coordinates of the center point. The map's zoom level is set by calling the mMap.setZoom() method and pass it to the zoom level.
-
The other methods in the class implement the lifecycle methods for an activity. These methods are called when the activity starts, pauses, stops, resumes, is destroyed, or is low on memory.