我有以下代码来设置应用程序的当前位置:
public void setLocation(double latitude, double longitude) {
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (locationManager.getProvider(providerName) != null) {
locationManager.removeTestProvider(providerName);
}
locationManager.addTestProvider(providerName, true, false, false,
false, false, false, false, Criteria.POWER_LOW,
Criteria.ACCURACY_FINE);
Location myloc = new Location(LocationManager.GPS_PROVIDER);
myloc.setLatitude(latitude);
myloc.setLongitude(longitude);
myloc.setTime(System.currentTimeMillis());
locationManager.setTestProviderEnabled(providerName, true);
locationManager.setTestProviderLocation(providerName, myloc);
}
@SuppressWarnings("deprecation")
public void set1001(View view) {
final double latitude = 40.718803;
final double longitude = -74.000193;
setLocation(latitude, longitude);
displayLocation();
}
set1001 是一个Button
点击动作。
问题是位置设置后会切换回当前位置。这个设置的位置代码是否必须像每秒左右一样不断运行?基本上,我希望将位置固定在我一直指定的坐标上。
谢谢你的帮助。