我需要在没有GPS的情况下为我的设备使用伪GPS坐标。我正在尝试使用本手册:http://developer.android.com/training/location/location-testing.html
但是导入com.google.android.gms.location.LocationClient不可用。据我所知,它已被弃用。但是现在如何实现模拟位置?
答案 0 :(得分:1)
答案 1 :(得分:1)
迈克尔的回答。
初始化GoogleApiClient:
private GoogleApiClient mGoogleApiClient;
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API).addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
连接客户端:
mGoogleApiClient.connect();
设置新位置:
Location location = new Location(LocationManager.GPS_PROVIDER);
location.setLatitude(48.446743);
location.setLongitude(52.44672);
location.setAccuracy(4.0f);
location.setElapsedRealtimeNanos(elapsedTimeNanos);
location.setTime(currentTime);
LocationServices.FusedLocationApi.setMockLocation(mGoogleApiClient, location);
完成后,需要断开客户端的连接:
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}