Skip to content

Show MapView

Show Map

The MapView package provides all the classes for Map Rendering. MapView is built following Android UI Framework practice and provides much flexibility for the developer. The following are some of the common MapView features.

  • Map Rendering - High quality Map Rendering View can be easily integrated into your application, CSM, or Cluster.
  • Flexible and Rich Styling Support - Flexible and high performance map styling support, designed for various navigation experience.
  • Location Info Rendering - Showing additional Geo-Spacial content on the map, like POI from our Search SDK, or any other content you would like to display.
  • Driving Mode - Rich and fine tuned feature set to enable drive mode for MapView, follow vehicle camera, auto-zoom based on vehicle speed and Location information.
  • Route Rendering and Navigation Support - Rendering Route and supporting full feature set required to enable a smooth navigation experience. More information can be referred to our Navigation module.

To Show MapView on your designed application, below are the steps to follow:

Step 1:

Add SDK life cycle managements for SDK. Please intialize SDK during onCreate(), and call SDK.dispose when onDestroy called.

Tip

Some features require additional permissions from Android system to work. These permissions include internet permission for streaming and cloud features, externalStorage read/write permission for embedded map data access, and location permission for driving and navigation. Please refer to SDKOption object definition. Providing an end point in SDKOption enables its cloud mode. Configuring the map data path (require permission) enables its embedded mode. If both end point and map data path are set, SDK will work in hybrid mode. To get a set of evaluation data, please contract Telenav sales team. SDKOptions must include apikey/apisecret to initialize our SDK.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Initalize SDK instance during application start
protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

       SDKOptions options = SDKOptions.builder()
            .setApiKey("#YOUR_API_KEY")
            .setApiSecret("#YOUR_API_SECRET")
            .setCloudEndPoint("#END_POINT")
            .build();
        NavSDKOptions navSDKOptions = NavSDKOptions.builder(options)
            .enableTraffic(true)
            .setTrafficExpireTime(60)
            .setTrafficRefreshTime(60)
            .build();                
        SDK.getInstance().initialize((Context)this, navSDKOptions);

        this.setContentView(R.layout.activity_example_entry);
        this.setSupportActionBar((Toolbar)this.findViewById(R.id.toolbar));
}
// Destory SDK instance when exit application
protected void onDestroy() {
    super.onDestroy()
    SDK.getInstance().dispose()
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Initalize SDK instance during application start
override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //initalize SDK
        val options:SDKOptions = SDKOptions.builder()
        .setApiKey("#YOUR_API_KEY")
        .setApiSecret("#YOUR_API_SECRET")
        .setCloudEndPoint("#END_POINT")
        .build()
        //set configuration
        val navSDKOptions = NavSDKOptions.builder(options)
        .setTrafficRefreshTime(60)
        .setTrafficExpireTime(60)
        .enableTraffic(true)
        .build()
        SDK.getInstance().initialize(this,navSDKOptions)
        setContentView(R.layout.activity_example_entry)
        setSupportActionBar(findViewById(R.id.toolbar))
}
//Destory SDK instance when exit application
override fun onDestroy() {
    super.onDestroy()
    SDK.getInstance().dispose()
}

Step 2:

Declare Mapview on the target layout.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SecondFragment">

<com.telenav.map.views.TnMapView
    android:id="@+id/map_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

Step 3:

Initalize MapView after View is created.

1
2
3
4
    public void onViewCreated(@NotNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        ((MapView)view.findViewById(R.id.map_view)).initialize(savedInstanceState);
    }
1
2
3
4
5
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        view.findViewById<MapView>(R.id.map_view).initialize(savedInstanceState)
    }

Step 4:

Build and Run your application on Device.

Step 5:

Now you should be able to see the map, pan/zoom operations are supported. Also, there are other subset APIs exposed, including: setZoomLevel and followVehicle().

Under follow vehicle mode, you can't pan, but when user try to pan the map, you will receive callback and make decision based on the situation. The API will be published later.

1
2
!!! tip  
    due to compilation configuration, our sdk is not compatiable with x86_64 laptop simulator yet. So please try on android devices.