I have a method which is responsible for returning a URL with latitude and longitude according to the search term, the method is as follows:
public String getUrlFromTermsSearch(String searchTerm, Context context,String baseUrl){
String url = "";
try {
Geocoder selected_place_geocoder = new Geocoder(context);
List<Address> address;
address = selected_place_geocoder.getFromLocationName(searchTerm,1);
if (address.size()>0) {
Address location = address.get(0);
String urlF = baseUrl+searchTerm+"/"+location.getLatitude()+"/"+location.getLongitude()+"";
url = urlF.replaceAll(" ","%20");
}else{
Log.d("error con Geocoder", ">>>: ");
}
} catch (Exception e) {
e.printStackTrace();
}
return url;
}
But at times it shows or returns an exception in this part:
selected_place_geocoder.getFromLocationName(searchTerm,1);
Which is
error geocoder timeout exception
How could I solve this situation?