我使用位置Api时遇到问题。我正在尝试使用以下代码从任何可用的提供程序获取位置:
//Définir ma localisation
final LocationManager manag = (LocationManager) ActivityRechercheConcession.this.getSystemService(Context.LOCATION_SERVICE);
//Choix du service de localisation en fonction de critères
Criteria crit = new Criteria();
crit.setCostAllowed(false);
crit.setAccuracy(1000); //précis à au moins 1km pret
final String choix_source = manag.getBestProvider(crit, true);
//demander la position courante
manag.requestLocationUpdates(choix_source, 10000, 0, new LocationListener(){
//Lors de la capture de la position
public void onLocationChanged(Location location) {
Log.i("LocationListener","New position from "+choix_source+": ("+location.getLatitude()+","+location.getLongitude()+")");
}
}
但是当我发送与仿真器控件的坐标时(如long:7.745304,lat:48.589326) 我只获取位置数据中的整数部分(如长7.0,纬度48.0) 因此,对这些值的计算方法完全是错误的。
为什么我会丢失这些数据的小数部分?
答案 0 :(得分:1)
Criteria.setAccuracy
方法只需要两个标记:ACCURACY_FINE
和ACCURACY_COARSE
,而不是您使用的绝对数值。我猜1000
在这里被解释为粗精度,因此你得到了修剪坐标。
换句话说,你应该使用:
crit.setAccuracy(Criteria.ACCURACY_FINE);
获得精确的坐标。
答案 1 :(得分:0)
问题来自Eclipse的Emulator Control,而不是来自代码。
要解决它,我必须通过添加以下行来正确配置eclipse.ini:
-Duser.language=en
对应我的语言环境所以我用过:
-Duser.language=fr
然后我不得不在我发出的价值中使用“昏迷”而不是“点”。 这样代码运行良好:D