-
gps issue
hi how do i make this work
it worked earlier but it seems i change something i don't remember
Code:
public void onLocationChanged(Location loc) {
loc.getLatitude();
loc.getLongitude();
if(loc.getLatitude()== 31.30){
if (loc.getLongitude()== 34.45){
Toast.makeText(Gps1Activity.this, "israel", Toast.LENGTH_LONG).show();
}
}
Toast.makeText(Gps1Activity.this, "error", Toast.LENGTH_LONG).show();
}
in the morning it gave me "Israel"
but now error why? could it be because it's cloudy now(now it's night)?
thanks for the helpers
-
Re: gps issue
It might help if you changed the message so that it toasted the actual coordinates instead of just saying "error".
-
Re: gps issue
For debugging you should print out the contents of the loc variable so you know what you are comparing against.
If you properly align the {}s it looks like you will always get the error message part
Code:
public void onLocationChanged(Location loc) {
loc.getLatitude();
loc.getLongitude();
if(loc.getLatitude()== 31.30){
if (loc.getLongitude()== 34.45){
Toast.makeText(Gps1Activity.this, "israel", Toast.LENGTH_LONG).show();
}
}
Toast.makeText(Gps1Activity.this, "error", Toast.LENGTH_LONG).show();
}
A problem with comparing floating point numbers using == can be that 35.000004 != 35.0
but that is probably very close to the waypoint you are looking at.
I would use something like: Math.abs(lat - 35.0) < 0.0001