In my app, I have to take in a user address (US). The user needs to type in a valid address. How can I achieve this? Is there any library which can help me with the names of states, cities and street names? I would like to use autotype if possible. I read GeoCoding but I don't think it will help me as the user is not entering the address from the current location.
This is what I do to find a location using Google API. Maybe it will help you:
Geocoder geoCoder = new Geocoder(context, Locale.getDefault());
try {
List<Address> addresses =
geoCoder.getFromLocationName(travel.getAddress() + "," +
travel.getCity() + "," + travel.getState() + "," + travel.getCountry(), 3);
if (addresses.size() > 0) {
point = new GeoPoint(
(int) (addresses.get(0).getLatitude() * 1E6),
(int) (addresses.get(0).getLongitude() * 1E6));
travel.setLatitude(String.valueOf(point.getLatitudeE6()));
travel.setLatitude(String.valueOf(point.getLongitudeE6()));
long res = travel.update(context, null);
if (res < 1){
result = false;
}
}
} catch (IOException e) {
e.printStackTrace();
result = false;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With