Revision as of 11:46, 31 March 2014 by croozeus (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Utilizing HERE Maps with components using v4 fragments

From Nokia Developer Wiki
Jump to: navigation, search
Featured Article
30 Mar

This article explains how to use HERE Maps API with v4 fragments.

Article Metadata
Code Example
Source file: MapsInTabs
Created: symbianyucca (10 Mar 2014)
Last edited: croozeus (31 Mar 2014)



The HERE Maps API in general is designed to work with android.app.Fragment derived fragments, you could see this by checking the base classed with the API parts such as com.here.android.mapping.MapFragment.

If you want to use the android.support.v4.app.Fragment, you cannot use the normal Map fragment in it. In this wiki article, I describe two alternatives with which you can use the HERE Maps API with APIs expecting you to use v4 fragments.

Parts for the solution were originally provided by an answer in Stack Overflow.

Using the Map View instead of Map Fragment

Instead of using the map through fragment, you can use the com.here.android.mapping.MapView instead, and then use findViewById() to locate it from the layout. And then for the initialization, you would need to initialize the Factory, and then use the function from it for creating the map instance, which you can add into the view element.

MapFactory.initFactory(getActivity().getApplicationContext(), new FactoryInitListener() {
public void onFactoryInitializationCompleted(InitError error) {
if(error == InitError.NONE){
mMap = (Map) mMapView.getMap();
mMap.setCenter(MapFactory.createGeoCoordinate(48.8567, 2.3508), MapAnimation.NONE);

Using the Compatibility Fragment

There is also another possible way where you can use com.here.android.mapping.MapCompatibilityFragment class instead of the com.here.android.mapping.MapFragment. By using this approach, you just need to simply change the API without changing the existing code.

Note that you can also use this API with API level 10 as mentioned in API docs.

Example code

Full example code which is utilising both method with Tabs can be found from GitHub: MapsInTabs

This page was last modified on 31 March 2014, at 11:46.
113 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.