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

5145
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
GSauers
Occasional Contributor
I know this thread is old, but has a solution been found to using multiple maps in offline mode?

I am trying to add multiple maps to a MapView, but the screen only allows me to see the first map that is loaded. I can tell the second map loads, but I cannot scroll or navigate to the area of the second map.

Any help is appreciated. Thanks.
0 Kudos
GSauers
Occasional Contributor
Any update on this issue? I am still looking for a solution.
Thanks.
0 Kudos
DavidAstle
New Contributor

Has the issue of the multiple map views been resolved with the latest release ?  If so where can I find concise documentation on it.

David A.

GIS Analyst

Southern Cross Inc.

0 Kudos
ShellyGill1
Esri Contributor

Hi David,

Yes, the current release of ArcGIS Runtime SDK for Android (10.2.8) supports multiple MapViews in one app, or within the same layout if you want. I think this has been true for a number of releases, but I couldn't say for sure myself exactly what release this changed at.

Regards,

Shelly

0 Kudos
GSauers
Occasional Contributor

Thank you for the reply, is there any documentation on how to add a second map layer to an existing map layer?

Thanks.

0 Kudos
DavidAstle
New Contributor

Shelley,

We tried updating the SDK and it still doesn't work. We are using two separate activities that host the same map vew fragment. When we launch the first map view it works ok. We switch activities and second map view is working as well, but when we switch back to the first activity map it freezes. That is the primary error we see. Sometimes the second map will work ok, but when we switch back to the first one, it will freeze. Is there another factor we are missing.

David Astle, GIS Analyst

Southern Cross<http://southerncrossinc.com/index.html> | O: 770-326-6476 | M: 470-539-2139

3175 Corners North Ct. Peachtree Corners, GA 30071

Trusted Partner of Utilities Everywhere Since 1946

0 Kudos
AlexanderNohe1
Occasional Contributor III

Can you post any errors that logcat is showing?

0 Kudos
BillMyers
New Contributor II

Are multiple maps supported in the current version (100.1.0)? 100.1.0 

William H Myers
0 Kudos
AlexanderNohe1
Occasional Contributor III

bmyers5000‌,

Can you be a little more descriptive on what you mean by multiple maps?  Do you mean multiple maps in the same app or in the same view?

Thanks,

Alexander

0 Kudos
GSauers
Occasional Contributor

Not sure if this is what Bill is looking for, but I am looking for a way to show multiple offline tpk files in the same view. I want to be able to load my tablet with multiple map files and have them all display at one time. Right now, I can only show one map at a time and the user has to select which map they want to see.

Thanks.

0 Kudos