Select to view content in your preferred language

Need best practice advice for using several maps in an Android app

5719
22
01-25-2012 05:50 AM
FredrikPaasche
New Contributor
I need to display a map several places in an Android app. My problem is that the first map I create works fine, but the second one will not display the current position or any graphic markers. The maps are in different activities.

I have tried to call map.recycle() when pausing the first activity, and this makes the second map display the graphic markers, but then I need to recreate the first map all over again, which causes me to think that I am going the wrong way about this. 

The code used to create the maps are identical in the two activities, except for the resource IDs which are different.

What is the best way (or correct way) to have two maps active in two different activities in the same app? What should be done in the onCreate, onDestroy, onPause and onResume?

Example code:

// Credentials to access the map
String tokenServiceUrl = "https://somewhere/arcgis/tokens";
String userName = "secret";
String password = "secret";
UserCredentials credentials =  new UserCredentials();
credentials.setTokenServiceUrl(tokenServiceUrl);
credentials.setUserAccount(userName, password);
 
// Initialize the map
map = (MapView) findViewById(R.id.closebyMap);
String mapUrl = "http://path_to_mapserver";
ArcGISTiledMapServiceLayer tiledLayer = new ArcGISTiledMapServiceLayer(mapUrl, credentials);
map.addLayer(tiledLayer);
graphicsLayer = new GraphicsLayer();
map.addLayer(graphicsLayer);  

Then I set up a setOnStatusChangedListener, wait until I get INITIALIZED, then add graphic markers and start localization. When receiving location changed, I zoom the map to the current location.

Any help will be greatly appreciated!
0 Kudos
22 Replies
AlexanderNohe1
Honored Contributor

sauegr01‌,

So to confirm:

You have one map view with multiple TPKs and you are unable to display more than one TPK at once?

This is on Runtime 100.1?

0 Kudos
GSauers
Frequent Contributor

In the previous version of the SDK, 10.2.X, you could only show one tpk file at a tile. I am wondering, and I think Bill is wondering the same thing, if in the new 100.1, has this feature/capability been added?

If I have 2 maps, one for WashingtonDC.tpk and one for BaltimoreMD.tpk, in the 10.2.X, you could only show one at a time. We are curious if you can have both .tpks showing at the same time, so if you move from Washington to Baltimore, you would not have to reload the Baltimore map when you reach the extent of the Washington map. Does that make sense?

Thanks.

0 Kudos
AlexanderNohe1
Honored Contributor

This does make sense.  I haven't had a chance to experiment with this yet, but I will try it out when I get some time.  Additionally, have you all considered MMPKs? (Added at version 100)  This gives you a bit more flexibility with what data can be passed to the device and accessed offline.  Although, there is no imagery support at this time with mmpks, it is in the works.

0 Kudos