Android LocationManager 获取坐标的整数值(而双精度值)
我在使用 Location 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()+")");
}
}
但是当我使用模拟器控件发送坐标时(例如长:7.745304,纬度:48.589326) 我只获取位置数据中的整数部分(例如 long 7.0、lat 48.0) 所以这些值的计算方法是完全错误的。
为什么我会丢失这些数据的小数部分?
I have an issue using the Location Api. I'm trying to get the Location from any of the provider available, using this code:
//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()+")");
}
}
But when I'm sending coordinate with the Emulator Control (like long: 7.745304, lat : 48.589326)
I'm only getting the integer part in my Location data (like long 7.0, lat 48.0)
So calculation method on those value are totally false.
Why do I lose the fractional part of those data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Criteria.setAccuracy
方法仅采用两个标志:ACCURACY_FINE
和ACCURACY_COARSE
,而不是您使用的绝对数值。我猜1000
在这里被解释为粗略精度,因此您会得到修剪后的坐标。换句话说,您应该使用:
来获取精确的坐标。
The
Criteria.setAccuracy
method takes only two flags:ACCURACY_FINE
andACCURACY_COARSE
, not absolute numeric value you have used. I guess1000
is interpreted as coarse accuracy here and hence you get trimmed coordinates.In other words, you should use:
to obtain precise coordinates.
问题来自 Eclipse 的模拟器控制而不是代码。
有些要解决它,我必须通过添加此行来正确配置 eclipse.ini:
对应于我的语言环境,所以我使用 :
然后我必须在发送的值中使用“coma”而不是“dot”。
这样代码就可以正常运行了:D
The problem was coming from Eclipse's Emulator Control and not from the code.
Some to resolve it I have to rightly configure the eclipse.ini by adding this line:
corresponding to my locale so I used :
and afterwards I had to use "coma" instead of "dot" in value I sended.
That way the code is running well :D