您正在开发一个将设置坐标(经度和纬度)的应用程序.它必须显示我的位置,因为我在那个坐标.它类似于位置欺骗者..
http://www.androidzoom.com/android_applications/tools/location-spoofer_gkmc.html
但我没有这样做..这是我的代码..请任何人帮助我.
public class Mock extends MapActivity
{
private LocationManager lm;
private LocationListener locationListener;
private MapView mapView;
String mocLocationProvider;
private MapController mc;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//---use the LocationManager class to obtain GPS locations---
lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener();
mocLocationProvider=LocationManager.GPS_PROVIDER;
lm.addTestProvider(mocLocationProvider, false, false,false, false, true, true, true, 0, 5);
lm.setTestProviderEnabled(mocLocationProvider,true);
lm.requestLocationUpdates(mocLocationProvider,0,0,locationListener);
mapView = (MapView) findViewById(R.id.mapview1);
mc = mapView.getController();
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
private class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc) {
loc = new Location(mocLocationProvider);
Double latitude = 1.352566007;
Double longitude = 103.78921587;
//Double altitude = Double.valueOf(parts[2]);
loc.setLatitude(latitude);
loc.setLongitude(longitude);
loc.setTime(System.currentTimeMillis());
lm.setTestProviderLocation(mocLocationProvider, loc);
mc.setZoom(16);
mapView.invalidate();
}
@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
}
}
}
最佳答案 我会用这个方法
http://developer.android.com/guide/developing/tools/ddms.html#emulator-control.没试过这个:
http://code.google.com/p/android/issues/detail?id=915