JimMeuse

Location Service troubles

Discussion created by JimMeuse on Feb 21, 2013
I am attempting to come up the ArcGIS Android learning curve by developing a few simple applications which do only one particular task..In this case I am trying to have a map which will open at the users location.  I looked at the Nearby sample, which works as is on my Nexus 7. I created another application using portions of the Nearby code but when the map opens, all I see is a grid.  Here is the code I am using.

public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
 
  // Retrieve the map and initial extent from XML layout
  mMapView = (MapView)findViewById(R.id.map);
  /* create a @ArcGISTiledMapServiceLayer */
  tileLayer = new ArcGISTiledMapServiceLayer(
    "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");
  // Add tiled layer to MapView
  mMapView.addLayer(tileLayer);
 
  //now i will try to add code to zoom to current location
  mMapView.setOnStatusChangedListener(new OnStatusChangedListener(){
   private static final long serialVersionUID = 1L;
   public void onStatusChanged(Object source, STATUS status){
    if(source == mMapView && status==STATUS.INITIALIZED){
     LocationService ls = mMapView.getLocationService();
     ls.setAutoPan(false);
     ls.setLocationListener(new LocationListener(){
      boolean locationChanged = false;
      public void onLocationChanged(Location loc){
       if(!locationChanged){
        locationChanged = true;
        double locx = loc.getLatitude();
        double locy = loc.getLongitude();
        Point wgspoint = new Point(locx, locy);
        Point mapPoint = (Point) GeometryEngine.project(wgspoint, SpatialReference.create(4326), mMapView.getSpatialReference());
        Unit mapUnit = mMapView.getSpatialReference().getUnit();
        double zoomWidth = Unit.convertUnits(SEARCH_RADIUS, Unit.create(LinearUnit.Code.MILE_US), mapUnit);
        Envelope zoomExtent = new Envelope(mapPoint, zoomWidth, zoomWidth);
        mMapView.setExtent(zoomExtent);
       }
      }
      public void onProviderDisabled(String arg0){
      
      }
      public void onProviderEnabled(String arg0){
      
      }
      public void onStatusChanged(String arg0, int arg1, Bundle arg2){
      
      }
     });
     ls.start();
    }
   }
  });
 
  }
 
@Override
protected void onPause() {
  super.onPause();
  mMapView.pause();
}

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

}

the main.xml file has:

    <com.esri.android.map.MapView
    android:id="@+id/map"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
   </com.esri.android.map.MapView>

What am I missing?  Thanks.

Outcomes