Adding OpenStreetMap to HelloWorld in 10.2.2

2006
1
03-30-2014 03:42 PM
PattyJula
New Contributor II
Hello, I want to add an OpenStreetMap tile service layer to the Esri Android HelloWorld app. I'm following the OpenStreetMap documentation here. Find the relevant code below:

public class HelloWorld extends Activity {
  MapView mMapView;

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mMapView = (MapView)findViewById(R.id.map);
    String[] tileServerURL = {"http://b.tile.cloudmade.com/{KEY}/1/256"};
    OpenStreetMapLayer tileLayer = new OpenStreetMapLayer(tileServerURL, 1, 16, "CloudMade", true);
    tileLayer.setKey("myKey"); 
 
    mMapView.addLayer(tileLayer); //when this line is commented out the app runs just fine


LogCat gives an EsriServiceException and the app closes when I include the code above in the app. I'm probably missing something minor? Can someone clue me in?

Thanks! Patty
0 Kudos
1 Reply
DanO_Neill
Occasional Contributor III
The reason why the app runs when you comment out the mMapView.addLayer(tileLayer) is that the MapView's basemap is set in XML. Open up the /res/layout/main.xml file and comment out all the mapoptions parameters. Your XML should look like this:

<!-- MapView layout, including basemap layer, initial center point, and zoom level --> 
<com.esri.android.map.MapView 
  android:id="@+id/map" 
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent" />


I can confirm that the url you provide resolves to http://b.tile.cloudmade.com/myKey/1/256 at runtime.

I responded to your GIS Stackexchange question as well.
0 Kudos