如何将位置推送到模拟器?

时间:2012-05-14 11:43:09

标签: android android-emulator

我想在模拟器中设置一个点作为当前位置?我在DDMS中使用位置控件,但它不起作用!有谁知道如何解决这个问题?在此先感谢!!

1 个答案:

答案 0 :(得分:0)

试试这个,

public class NL extends Activity {

    private LocationManager locmgr = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.nl);

        locmgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

     // Define a listener that responds to location updates
        LocationListener locationListener = new LocationListener() {
            public void onLocationChanged(Location loc) {
              // Called when a new location is found by the network location provider.
                Log.i("NOTIFICATION","onLocationChenged Triggered");

                Toast msg = Toast.makeText(NetworkLocator.this, "Lon: " + Double.toString(loc.getLongitude()) + " Lat: " + Double.toString(loc.getLatitude()), Toast.LENGTH_SHORT);
                msg.show();
            }

            public void onStatusChanged(String provider, int status, Bundle extras) {}

            public void onProviderEnabled(String provider) {}

            public void onProviderDisabled(String provider) {}
          };

        // Register the listener with the Location Manager to receive location updates
        locmgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
    }
}

摘自Android - Unable to get the gps location on the emulator