title: Arcgis Map : Get Current Location Error , Not displaying my current location
body: <p>Hie, </p>
  
  <p>I tried this sample code that one of the person who gave me this in my other question in stack overflow. I tried using this code but when i run the applicationn, it doesnt locate my current device and it doesnt even display a dot of my location .. The code does not give me any red underline errors but i am unable to locate the current location i am at.</p>
  
  <p>What did i miss out? is there anyone who has a sample working source code file that i can download from to get my current device location??</p>
  
  <p>the codes i  used is as followed, </p>
  
  <p>This is my <strong>MainActivity.class</strong></p>
  
  <pre><code>public class MainActivity 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.mapview);
       mMapView.addLayer(new ArcGISTiledMapServiceLayer(
           "http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"));
      mMapView = new MapView(this);
  
      LocationResult locationResult = new LocationResult(){
          @Override
          public void gotLocation(Location loc){
  
          }
      };  
      MyLocation mylocation = new MyLocation();
      mylocation.getLocation(this, locationResult);
  
  }
  </code></pre>
  
  <p>This is <strong>MyLocation.java</strong></p>
  
  <pre><code>public class MyLocation {
  Timer timer1;
  LocationManager lm;
  LocationResult locationResult;
  boolean gps_enabled=false;
  boolean network_enabled=false;
  
  public boolean getLocation(Context context, LocationResult result)
  {
      //I use LocationResult callback class to pass location value from MyLocation to user code.
      locationResult=result;
      if(lm==null)
          lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
  
      //exceptions will be thrown if provider is not permitted.
      try{gps_enabled=lm.isProviderEnabled(LocationManager.GPS_PROVIDER);}catch(Exception ex){}
      try{network_enabled=lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);}catch(Exception ex){}
  
      //don't start listeners if no provider is enabled
      if(!gps_enabled &amp;&amp; !network_enabled)
          return false;
  
      if(gps_enabled)
          lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListenerGps);
      if(network_enabled)
          lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListenerNetwork);
      timer1=new Timer();
      timer1.schedule(new GetLastLocation(), 20000);
      return true;
  }
  
  LocationListener locationListenerGps = new LocationListener() {
      public void onLocationChanged(Location location) {
          timer1.cancel();
          locationResult.gotLocation(location);
          lm.removeUpdates(this);
          lm.removeUpdates(locationListenerNetwork);
      }
      public void onProviderDisabled(String provider) {}
      public void onProviderEnabled(String provider) {}
      public void onStatusChanged(String provider, int status, Bundle extras) {}
  };
  
  LocationListener locationListenerNetwork = new LocationListener() {
      public void onLocationChanged(Location location) {
          timer1.cancel();
          locationResult.gotLocation(location);
          lm.removeUpdates(this);
          lm.removeUpdates(locationListenerGps);
      }
      public void onProviderDisabled(String provider) {}
      public void onProviderEnabled(String provider) {}
      public void onStatusChanged(String provider, int status, Bundle extras) {}
  };
  
  class GetLastLocation extends TimerTask {
      @Override
      public void run() {
           lm.removeUpdates(locationListenerGps);
           lm.removeUpdates(locationListenerNetwork);
  
           Location net_loc=null, gps_loc=null;
           if(gps_enabled)
               gps_loc=lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
           if(network_enabled)
               net_loc=lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
  
           //if there are both values use the latest one
           if(gps_loc!=null &amp;&amp; net_loc!=null){
               if(gps_loc.getTime()&gt;net_loc.getTime())
                   locationResult.gotLocation(gps_loc);
               else
                   locationResult.gotLocation(net_loc);
               return;
           }
  
           if(gps_loc!=null){
               locationResult.gotLocation(gps_loc);
               return;
           }
           if(net_loc!=null){
               locationResult.gotLocation(net_loc);
               return;
           }
           locationResult.gotLocation(null);
      }
  }
  
  public static abstract class LocationResult{
      public abstract void gotLocation(Location location);
  }
  }
  </code></pre>