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.
-
How precise does the address need to be? Is it just zip code and state, or do you need city names and street addresses as well. Keep in mind that the same place can have multiple valid addresses because, for instance, a street may be a highway with a number that is also named ex: highway 10 is also called main st where it runs through Springfield. – ethan Jan 03 '12 at 22:22
-
It need to be precise..How GPS device does it? It has State,City and street number where user type in and then the gps find the address and show it to the user. If user agrees than it goes on to find the route. I want the same thing. – Dave George Jan 03 '12 at 22:30
3 Answers
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;
}

- 9,844
- 3
- 34
- 66
There are various ways to clean up address input and to standardize it into the expected format. But the only real way to validate an address to ensure that it's both real and correct is to use an address verification service.
Standardizing an address is all about ensuring things look good--like formatting and standardizing a telephone number or email address. But having data that only looks good isn't enough. You need data that is good. As an example, would you accept an order if a user provides a credit card that might be good? Or do you want a credit card that is good? It's the same with addresses. If you're collecting an address, it would sure be nice to know that it's real, deliverable, and can be used for your intended purpose. Otherwise, it's just junk data--garbage in, garbage out.
Fortunately in your case, because the user is on an Android-based device, they will most likely have internet connectivity which allows you to perform a query to a 3rd-party address verification service. There are a number of services out there that provide street address verification. I'm the founder of one called SmartyStreets. Our LiveAddress API might just be what you're looking for. And, depending upon your volume and business, it may very well be completely free as well. If not, no big deal, there are other services out there that you can utilize.

- 1,048,767
- 296
- 4,058
- 3,343

- 5,207
- 32
- 31