1
我已經做了一個程序,以找到當前位置使用GPS在Android模擬器工作正常,並顯示正確的緯度和經度,我發送從Eclipse模擬器控制,但是有可能在模擬器中的GPS可能單獨顯示我的當前位置,即以一種方式跟蹤我的位置並單獨顯示它,而無需通過模擬器控件發送它。Android模擬器中的GPS可以跟蹤我當前的位置嗎?
下面是代碼:
package location.finder;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;
public class LocationFinderActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LocationManager locationManager= (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new loclistener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener);
}
public class loclistener implements LocationListener {
public void onLocationChanged(Location location){
String loc ="Latitude = " + location.getLatitude() +" Longitude = " + location.getLongitude();
Toast.makeText(getApplicationContext(),loc,Toast.LENGTH_SHORT).show();
}
public void onStatusChanged(String provider , int status, Bundle extras)
{
}
public void onProviderEnabled(String provider)
{
Toast.makeText(getApplicationContext(),"Gps Enabled",Toast.LENGTH_SHORT).show();
}
public void onProviderDisabled(String provider)
{
Toast.makeText(getApplicationContext(),"Gps Disabled",Toast.LENGTH_SHORT).show();
}
}
}