在安卓系统中,如何使用虚假GPS位置?

4

大家好,我正在开发一款应用程序,它将设置坐标(纬度和经度)。并且必须显示我的位置,就像我在那些坐标上一样。这与定位欺骗器类似。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
    }
}    
}
2个回答

2

1
嗨,Kwa...我想在真实设备上执行此操作,而不是在模拟器上。 - user458295
5
Downvote to BGS - no offense. Should have followed up on the user's question here. Yes, you can do this on the real device. Just enable "mock locations" in settings, and follow the guide at the first URL in this answer under how to run DDMS. You'll have to enable USB debugging as well for the computer to recognize the device. Make sure to have installed the OEM USB drivers for your phone (which I'm sure you've already done).对BGS进行负面评价,无意冒犯。应该在这里跟进用户的问题。是的,您可以在实际设备上执行此操作。只需在设置中启用“模拟位置”,并按照本答案中第一个URL下如何运行DDMS的指南操作即可。还需要启用USB调试功能,以便计算机能够识别设备。请确保已安装适用于您的手机的OEM USB驱动程序(我相信您已经完成了此步骤)。 - Qix - MONICA WAS MISTREATED
2
是的,我知道我晚了大约一年,但我想有人可能会觉得这有帮助。 - Qix - MONICA WAS MISTREATED
这是Qix...它是...现在是2013年,我发现它很有用。 - Michael 'Maik' Ardan

0

您可以通过在Eclipse中使用DDMS来设置真实设备上的坐标,就像在模拟器中一样。

请确保在您的设备上启用了“模拟位置”的功能。您可以在设置 > 应用程序 > 开发 > 允许模拟位置中找到该设置。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接