0

I want a sample code that is put in place to allow us to locate the plate was the same as a navigation system, search by name we put to it. Position from where we are to the destination that we set.

2 Answers2

0

use this method

 /**
 * Get list of address by latitude and longitude
 * @return null or List<Address>
 */
public List<Address> getGeocoderAddress(Context context)
{
    if (location != null)
    {
        Geocoder geocoder = new Geocoder(context, Locale.ENGLISH);
        try 
        {
            List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
            return addresses;
        } 
        catch (IOException e) 
        {
            //e.printStackTrace();
            Log.e("Error : Geocoder", "Impossible to connect to Geocoder", e);
        }
    }

    return null;
}

regards maven

Maveňツ
  • 1
  • 12
  • 50
  • 89
0

You can use following method-

public String getLatLonByAddress(String addr) {

        Geocoder geoCoder = new Geocoder(this);
        List<Address> address = null;

        try {
            address = geoCoder.getFromLocationName(addr, 5);
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        if (address == null) {
            return null;
        }
        Address location = address.get(0);

        return location.getLatitude() + " / " + location.getLongitude();
    }
Mohit Rajput
  • 439
  • 3
  • 18