Example usage for android.location Geocoder getFromLocationName

List of usage examples for android.location Geocoder getFromLocationName

Introduction

In this page you can find the example usage for android.location Geocoder getFromLocationName.

Prototype

public List<Address> getFromLocationName(String locationName, int maxResults) throws IOException 

Source Link

Document

Returns an array of Addresses that are known to describe the named location, which may be a place name such as "Dalvik, Iceland", an address such as "1600 Amphitheatre Parkway, Mountain View, CA", an airport code such as "SFO", etc..

Usage

From source file:com.taw.gotothere.GoToThereActivity.java

/**
 * Geocode the location the user typed into the search box, and centre the map
 * on it./*from   w w w.  ja  v  a  2s .c  o m*/
 */
private void geocodeResult(String address) {
    Log.d(TAG, "geocodeResult()");
    Geocoder geo = new Geocoder(this, Locale.getDefault());
    try {
        List<Address> addresses = geo.getFromLocationName(address, 10); // Hmmmm, 1?
        if (addresses.size() > 0) {
            GeoPoint pt = new GeoPoint((int) (addresses.get(0).getLatitude() * 1e6),
                    (int) (addresses.get(0).getLongitude() * 1e6));
            directionsImageView.setEnabled(true);
            navigationOverlay.setSelectedLocation(pt, this);
            map.getController().animateTo(pt);
            startMarkerPlacement();

            searchTextView.setText(address);
        } else {
            Toast.makeText(this, R.string.error_not_found_text, Toast.LENGTH_SHORT).show();
            searchTextView.setText(null);
        }
    } catch (IOException ioe) {
        Log.e(TAG, "Could not geocode '" + address + "'", ioe);
        Toast.makeText(this, R.string.error_general_text, Toast.LENGTH_SHORT).show();
    }
}

From source file:org.onebusaway.android.report.ui.InfrastructureIssueActivity.java

/**
 * Converts plain address string to Location object
 *
 * @param addressString takes address string
 * @return Location of given address String
 *//* w  ww . ja  v a2  s  .c o m*/
public Location getLocationByAddress(String addressString) {
    Geocoder coder = new Geocoder(this);
    List<Address> addressList;
    Location location;

    try {
        addressList = coder.getFromLocationName(addressString, 3);
        if (addressList == null || addressList.size() == 0) {
            return null;
        }
        Address address = addressList.get(0);

        location = new Location("");
        location.setLatitude(address.getLatitude());
        location.setLongitude(address.getLongitude());

        return location;
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:tw.com.geminihsu.app01.fragment.Fragment_PickUpMerchandiseStation.java

private void parserAddressToGPS() {

    Geocoder fwdGeocoder = new Geocoder(getActivity());

    if (departure_detail == null) {
        String departure = departure_address.getText().toString();

        List<Address> departure_locations = null;
        try {/*www . j a  va  2 s  .  c om*/
            departure_locations = fwdGeocoder.getFromLocationName(departure, 10);
        } catch (IOException e) {
        }

        departure_detail = new LocationAddress();
        if (departure_locations.size() > 0) {
            departure_detail.setLongitude(departure_locations.get(0).getLongitude());
            departure_detail.setLatitude(departure_locations.get(0).getLatitude());
            departure_detail.setAddress(departure);
            departure_detail.setLocation(departure);
            departure_detail.setCountryName(departure_locations.get(0).getCountryName());
            departure_detail.setLocality(departure_locations.get(0).getLocality());
            departure_detail.setZipCode(departure_locations.get(0).getPostalCode());
        }
    }
    String stop = stop_address.getText().toString();

    if (stop_detail == null) {
        List<Address> stop_locations = null;
        try {
            stop_locations = fwdGeocoder.getFromLocationName(stop, 10);
        } catch (IOException e) {
        }

        Log.e("", "Stop zipCode:" + stop_locations.get(0).getPostalCode());
        stop_detail = new LocationAddress();
        if (stop_locations.size() > 0) {
            stop_detail.setLongitude(stop_locations.get(0).getLongitude());
            stop_detail.setLatitude(stop_locations.get(0).getLatitude());
            stop_detail.setAddress(stop);
            stop_detail.setLocation(stop);
            stop_detail.setCountryName(stop_locations.get(0).getCountryName());
            stop_detail.setLocality(stop_locations.get(0).getLocality());
            stop_detail.setZipCode(stop_locations.get(0).getPostalCode());
        }
    }
    String destination = destination_address.getText().toString();

    if (destination_detail == null) {
        List<Address> destination_locations = null;
        try {
            destination_locations = fwdGeocoder.getFromLocationName(destination, 10);
        } catch (IOException e) {
        }

        destination_detail = new LocationAddress();
        if (destination_locations.size() > 0) {
            destination_detail.setLongitude(destination_locations.get(0).getLongitude());
            destination_detail.setLatitude(destination_locations.get(0).getLatitude());
            destination_detail.setAddress(destination);
            destination_detail.setLocation(destination);
            destination_detail.setCountryName(destination_locations.get(0).getCountryName());
            destination_detail.setLocality(destination_locations.get(0).getLocality());
            destination_detail.setZipCode(destination_locations.get(0).getPostalCode());
        }
    }

}

From source file:tw.com.geminihsu.app01.fragment.Fragment_PickUpAirPlane.java

private String getTrainStationZip(String address) {

    Geocoder fwdGeocoder = new Geocoder(getActivity());

    String zipCode = "";

    String departure = address;//from w  w w .jav  a2 s  .c o m

    List<Address> departure_locations = null;
    try {
        departure_locations = fwdGeocoder.getFromLocationName(departure, 10);
    } catch (IOException e) {
    }

    zipCode = departure_locations.get(0).getPostalCode();

    return zipCode;
}

From source file:tw.com.geminihsu.app01.fragment.Fragment_PickUpAirPlane.java

private void parserAddressToGPS() {

    Geocoder fwdGeocoder = new Geocoder(getActivity());

    if (departure_detail == null) {
        String departure = departure_address.getText().toString();

        List<Address> departure_locations = null;
        try {//from w  w  w.  j av a  2s .  c o  m
            departure_locations = fwdGeocoder.getFromLocationName(departure, 10);
        } catch (IOException e) {
        }

        departure_detail = new LocationAddress();
        if (departure_locations.size() > 0) {
            departure_detail.setLongitude(departure_locations.get(0).getLongitude());
            departure_detail.setLatitude(departure_locations.get(0).getLatitude());
            departure_detail.setAddress(departure);
            departure_detail.setLocation(departure);
            departure_detail.setCountryName(departure_locations.get(0).getCountryName());
            departure_detail.setLocality(departure_locations.get(0).getLocality());
            departure_detail.setZipCode(departure_locations.get(0).getPostalCode());
        }
    }
    String stop = stop_address.getText().toString();

    if (stop_detail == null) {
        List<Address> stop_locations = null;
        try {
            stop_locations = fwdGeocoder.getFromLocationName(stop, 10);
        } catch (IOException e) {
        }

        //Log.e("", "Stop zipCode:" + stop_locations.get(0).getPostalCode());
        stop_detail = new LocationAddress();
        if (stop_locations.size() > 0) {
            stop_detail.setLongitude(stop_locations.get(0).getLongitude());
            stop_detail.setLatitude(stop_locations.get(0).getLatitude());
            stop_detail.setAddress(stop);
            stop_detail.setLocation(stop);
            stop_detail.setCountryName(stop_locations.get(0).getCountryName());
            stop_detail.setLocality(stop_locations.get(0).getLocality());
            stop_detail.setZipCode(stop_locations.get(0).getPostalCode());
        }
    }
    String destination = destination_address.getText().toString();

    if (destination_detail == null) {
        List<Address> destination_locations = null;
        try {
            destination_locations = fwdGeocoder.getFromLocationName(destination, 10);
        } catch (IOException e) {
        }

        destination_detail = new LocationAddress();
        if (destination_locations.size() > 0) {
            destination_detail.setLongitude(destination_locations.get(0).getLongitude());
            destination_detail.setLatitude(destination_locations.get(0).getLatitude());
            destination_detail.setAddress(destination);
            destination_detail.setLocation(destination);
            destination_detail.setCountryName(destination_locations.get(0).getCountryName());
            destination_detail.setLocality(destination_locations.get(0).getLocality());
            destination_detail.setZipCode(destination_locations.get(0).getPostalCode());
        }
    }

}

From source file:tw.com.geminihsu.app01.fragment.Fragment_PickUpTrain.java

private String getTrainStationZip(String address) {

    Geocoder fwdGeocoder = new Geocoder(getActivity());

    String zipCode = "";
    String departure = address;/*from w  w  w.  ja  v  a 2s .  c  o  m*/

    List<Address> departure_locations = null;
    try {
        departure_locations = fwdGeocoder.getFromLocationName(departure, 10);
    } catch (IOException e) {
    }

    zipCode = departure_locations.get(0).getPostalCode();

    return zipCode;
}

From source file:tw.com.geminihsu.app01.fragment.Fragment_PickUpTrain.java

private void parserAddressToGPS() {

    Geocoder fwdGeocoder = new Geocoder(getActivity());

    if (departure_detail == null) {
        String departure = leave_train.getText().toString();

        List<Address> departure_locations = null;
        try {//w  w  w  .ja v a2s.c  o  m
            departure_locations = fwdGeocoder.getFromLocationName(departure, 10);
        } catch (IOException e) {
        }

        departure_detail = new LocationAddress();
        if (departure_locations.size() > 0) {
            departure_detail.setLongitude(departure_locations.get(0).getLongitude());
            departure_detail.setLatitude(departure_locations.get(0).getLatitude());
            departure_detail.setAddress(departure);
            departure_detail.setLocation(departure);
            departure_detail.setCountryName(departure_locations.get(0).getCountryName());
            departure_detail.setLocality(departure_locations.get(0).getLocality());
            departure_detail.setZipCode(departure_locations.get(0).getPostalCode());
        }
    }
    String stop = stop_train.getText().toString();

    if (stop_detail == null) {
        List<Address> stop_locations = null;
        try {
            stop_locations = fwdGeocoder.getFromLocationName(stop, 10);
        } catch (IOException e) {
        }

        //Log.e("", "Stop zipCode:" + stop_locations.get(0).getPostalCode());
        stop_detail = new LocationAddress();
        if (stop_locations.size() > 0) {
            stop_detail.setLongitude(stop_locations.get(0).getLongitude());
            stop_detail.setLatitude(stop_locations.get(0).getLatitude());
            stop_detail.setAddress(stop);
            stop_detail.setLocation(stop);
            stop_detail.setCountryName(stop_locations.get(0).getCountryName());
            stop_detail.setLocality(stop_locations.get(0).getLocality());
            stop_detail.setZipCode(stop_locations.get(0).getPostalCode());
        }
    }
    String destination = destination_train.getText().toString();

    if (destination_detail == null) {
        List<Address> destination_locations = null;
        try {
            destination_locations = fwdGeocoder.getFromLocationName(destination, 10);
        } catch (IOException e) {
        }

        destination_detail = new LocationAddress();
        if (destination_locations.size() > 0) {
            destination_detail.setLongitude(destination_locations.get(0).getLongitude());
            destination_detail.setLatitude(destination_locations.get(0).getLatitude());
            destination_detail.setAddress(destination);
            destination_detail.setLocation(destination);
            destination_detail.setCountryName(destination_locations.get(0).getCountryName());
            destination_detail.setLocality(destination_locations.get(0).getLocality());
            destination_detail.setZipCode(destination_locations.get(0).getPostalCode());
        }
    }

}