-3

我想在模拟器中设置一个点作为当前位置?我在 DDMS 中使用位置控制,但它不起作用!任何机构都知道如何解决这个问题?提前致谢!!

4

1 回答 1

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 - 无法在模拟器上获取 gps 位置

于 2012-05-14T12:22:57.510 回答