Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validating address input in Android

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.

like image 928
Dave George Avatar asked Jan 03 '12 04:01

Dave George


1 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;
        }
like image 193
sebastianf182 Avatar answered Nov 11 '22 11:11

sebastianf182