I’m building a location based application and I would like to avoid from this kind of location: “Tel Aviv, Tel Aviv, Israel” which is very not accurate.
I use the following condition before using a location:
if(!(this.location == null || this.location.getAccuracy() > 700))
// use the location
But I keep getting this locations (Tel Aviv, Tel Aviv, Israel), and Tel Aviv is not small enough to pass this condition.
I’m missing something? What’s wrong?
You haven’t specified a couple of parameters involved but I’ll give it a try.
The exact
Locationparameters depend on the source of that particularLocation, i.e. how it was obtained and using what geolocation source(s). For example:Locationwill have reliableaccuracyvalues.The accuracy you’ll receive from a location service represents a distance (in meters) from the reported location in which the device is likely to be in the moment the location was obtained.
So (if I understand your question correctly), I presume your using a low-accuracy method of obtaining current device location. You simply must switch to a source of
Locationwith greater accuracy.Please also note that the location-acquiring method (i.e. the service used to find the location as described above) used by the location service might actually not be able to provide accuracy for returned
Location. To understand what I mean by that consider a following scenario and their two outcomes – note that they both come from the same locating method based on Wi-Fi networks:You must make yourself prepared for such an occasion by testing if the accuracy is available at all. You can do this by issuing
Location.hasAccuracy(). If the returned value isfalse, you can’t callLocation.getAccuracy()(actually you can, but beware – it’ll return0!). So, your condition should be more like: