I use the class Geocoderto get the Latitude and Longitude value from my string address, which the user dials to EditText.
And interestingly, it returns results for a query such as "q", "qq", "n", "N". Is there any way to make this better? (Confirm or something else or use another service?)
if (!s.toString().isEmpty()) {
try {
List<Address> addresses = geocoder.getFromLocationName(s.toString(), 4);
if (addresses.size() > 0) {
Address userAddress = addresses.get(0);
double latitude = userAddress.getLatitude();
double longitude = userAddress.getLongitude();
mRestaurantLatLng = new LatLng(latitude, longitude);
if (userAddress != null) {
mPin.setVisibility(View.VISIBLE);
} else {
mPin.setVisibility(View.GONE);
mRestaurantLatLng = null;
}
} else {
mPin.setVisibility(View.GONE);
mRestaurantLatLng = null;
}
} catch (Exception e) {
e.printStackTrace();
}
source
share