我有如下代碼設置當前位置的應用程序:Android的固定位置應用
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
點擊動作。
問題是,在設置位置後,它將切換回當前位置。這個設置位置代碼是否必須不斷運行,就像每秒鐘左右一樣?基本上我希望位置固定在我指定的座標上。
感謝您的任何幫助。
你想一次設置座標,並使用他們很多次都沒有改變 – 2013-05-10 21:20:58
的例子是的,這是excatly我想做! – 2013-05-10 21:25:04