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
fi开发者_开发知识库nal 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?
The Criteria.setAccuracy
method takes only two flags: ACCURACY_FINE
and ACCURACY_COARSE
, not absolute numeric value you have used. I guess 1000
is interpreted as coarse accuracy here and hence you get trimmed coordinates.
In other words, you should use:
crit.setAccuracy(Criteria.ACCURACY_FINE);
to obtain precise coordinates.
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:
-Duser.language=en
corresponding to my locale so I used :
-Duser.language=fr
and afterwards I had to use "coma" instead of "dot" in value I sended. That way the code is running well :D
精彩评论