Fra*_*eye 4 android locationlistener google-play-services location-client
我使用的LocationClient效果很好.现在我正在尝试创建模拟位置(setMockMode(true)+ setMockLocation(mockLoc).但是我的LocationListener的onLocationChanged没有被调用.可能是什么问题?
我遵循了这个:http://developer.android.com/training/location/location-testing.html
脚步:
好的,所以你必须用setTime()和更新你的地点setElapsedRealtimeNanos().
一个完整的位置创建方法将如下所示:
@SuppressLint("NewApi")
public Location createLocation(double lat, double lng, float accuracy) {
// Create a new Location
Location newLocation = new Location(PROVIDER);
newLocation.setLatitude(lat);
newLocation.setLongitude(lng);
newLocation.setAccuracy(accuracy);
newLocation.setTime(System.currentTimeMillis());
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
newLocation.setElapsedRealtimeNanos(
SystemClock.elapsedRealtimeNanos());
}
return newLocation;
}
Run Code Online (Sandbox Code Playgroud)
这已经过测试,可与Nexus 5配合使用.
| 归档时间: |
|
| 查看次数: |
980 次 |
| 最近记录: |