0

I am trying to get latitude and longitude of user. I created a basic app. When I run it and feed latitude and longitude it restarts the OS in emulator. How can I fix this?

Here is my code

public class MGeolocationActivity extends Activity {
TextView tvLat;
TextView tvLong;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    tvLat = (TextView)findViewById(R.id.tvLat);
    tvLong = (TextView)findViewById(R.id.tvLong);

    LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    LocationListener ll = new myLocationListener();
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
}

class myLocationListener implements LocationListener {

    @Override
    public void onLocationChanged(Location location) {
        if(location != null) {
            double pLong = location.getLongitude();
            double pLat = location.getLatitude();
            tvLat.setText(Double.toString(pLat));
            tvLong.setText(Double.toString(pLong));
        }
    }

    @Override
    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub

    }

}
}
Om3ga
  • 30,465
  • 43
  • 141
  • 221

1 Answers1

2

It is a bug in emulator for sdk 2.3. Use 2.2 or other emulator

Vipul
  • 27,808
  • 7
  • 60
  • 75