pattyjula

Adding KML to HelloWorld

Discussion created by pattyjula on Mar 15, 2014
Hi, I want to add a KML to the HelloWorld Sample. I have been working with the code, but the KML is not displaying. Does anyone have a suggestion? I'm working on this for a GIS class. Thanks, Patty

package com.pattyjula.helloworld;

import android.app.Activity;
import android.os.Bundle;

import com.esri.android.map.MapView;
import com.esri.android.map.ags.ArcGISTiledMapServiceLayer;
import com.esri.android.map.event.OnStatusChangedListener;
import com.esri.android.map.ogc.KMLLayer;
import com.esri.core.geometry.SpatialReference;


public class HelloWorldActivity extends Activity {
 private String url = "http://dl.dropbox.com/u/2654618/kml/Wyoming.kml";
 MapView mMapView;

 /** Called when the activity is first created. */
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  ArcGISTiledMapServiceLayer tileLayer = new ArcGISTiledMapServiceLayer(
    "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");
  // Retrieve the map and initial extent from XML layout
  mMapView = (MapView)findViewById(R.id.map);
  mMapView.addLayer(tileLayer);

  mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {

     public void onStatusChanged(Object object, STATUS status){
                 if (status == OnStatusChangedListener.STATUS.INITIALIZED) {
                  SpatialReference sr = SpatialReference.create(102100);

                  KMLLayer kmlLink = new KMLLayer(url, sr, true);
                  kmlLink.refresh();
                  kmlLink.setVisible(true);
                  mMapView.addLayer(kmlLink);
                 }
                
             }
 });
 }
         
 protected void onPause() {
  super.onPause();
  mMapView.pause();
 }

 protected void onResume() {
  super.onResume();
  mMapView.unpause();
 }
 }

Outcomes