您好,我正在開發一個應用程序,它將設置座標(經度和緯度)。它必須顯示我的位置,因爲我在那個座標..它類似於位置欺騙.. http://www.androidzoom.com/android_applications/tools/location-spoofer_gkmc.html 但我沒有做到這一點..這裏是我的代碼..請任何人幫助我。在android中使用GPS的假位置
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
}
}
}
HI kwa ...我想在真實設備上做這個不在模擬器上 – user458295 2010-09-26 03:21:07
AnyOne幫助我..? – user458295 2010-09-26 05:43:21
Downvote BGS - 沒有冒犯性。應該在這裏跟蹤用戶的問題。是的,你可以在真實設備上做到這一點。只需在設置中啓用「模擬位置」,然後在如何運行DDMS的第一個URL中按照指南進行操作。您還必須啓用USB調試,以便計算機識別設備。確保已經爲您的手機安裝了OEM USB驅動程序(我相信您已經完成)。 – Qix 2011-08-24 10:29:06