Get the particular address using latitude and longitude

latitude and longitude to address
find location by latitude and longitude
latitude and longitude converter
latitude and longitude of my location
latitude and longitude google maps
get address from latitude and longitude android
get address from latitude and longitude google map api
coordinates converter

I need to know is there any API ,from where i can receive the Address of the current place.Using location Manager i have receive the latitude and longitude of the current place ,but i need the address.

I have tried the below api.

http://maps.googleapis.com/maps/api/geocode/json?latlng="+ lat + "," + lon + &sensor=true"

But it is not showing the exact place .Can somebody help me.@Thanks

From a Geocoder object, you can call the getFromLocation(double, double, int) method.

like :-

private String getAddress(double latitude, double longitude) {
        StringBuilder result = new StringBuilder();
        try {
            Geocoder geocoder = new Geocoder(this, Locale.getDefault());
            List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
            if (addresses.size() > 0) {
                Address address = addresses.get(0);
                result.append(address.getLocality()).append("\n");
                result.append(address.getCountryName());
            }
        } catch (IOException e) {
            Log.e("tag", e.getMessage());
        }

        return result.toString();
    }

Another best answer is here How to get city name from latitude and longitude coordinates in Google Maps?

Latitude and Longitude Finder on Map Get Coordinates, Lat long is a geographic tool which helps you to get latitude and longitude of a To make a search, use the name of a place, city, state, or address, or click the the angle between the straight line in the certain point and the equatorial plane. I need to know is there any API ,from where i can receive the Address of the current place.Using location Manager i have receive the latitude and longitude of the current place ,but i need the addr

I have created a class for getting address for a particular Lat, Long. You can use this :

public class getReverseGeoCoding {
    private String Address1 = "", Address2 = "", City = "", State = "", Country = "", County = "", PIN = "";

    public void getAddress() {
        Address1 = "";
        Address2 = "";
        City = "";
        State = "";
        Country = "";
        County = "";
        PIN = "";

        try {

            JSONObject jsonObj = parser_Json.getJSONfromURL("http://maps.googleapis.com/maps/api/geocode/json?latlng=" + Global.curLatitude + ","
                    + Global.curLongitude + "&sensor=true");
            String Status = jsonObj.getString("status");
            if (Status.equalsIgnoreCase("OK")) {
                JSONArray Results = jsonObj.getJSONArray("results");
                JSONObject zero = Results.getJSONObject(0);
                JSONArray address_components = zero.getJSONArray("address_components");

                for (int i = 0; i < address_components.length(); i++) {
                    JSONObject zero2 = address_components.getJSONObject(i);
                    String long_name = zero2.getString("long_name");
                    JSONArray mtypes = zero2.getJSONArray("types");
                    String Type = mtypes.getString(0);

                    if (TextUtils.isEmpty(long_name) == false || !long_name.equals(null) || long_name.length() > 0 || long_name != "") {
                        if (Type.equalsIgnoreCase("street_number")) {
                            Address1 = long_name + " ";
                        } else if (Type.equalsIgnoreCase("route")) {
                            Address1 = Address1 + long_name;
                        } else if (Type.equalsIgnoreCase("sublocality")) {
                            Address2 = long_name;
                        } else if (Type.equalsIgnoreCase("locality")) {
                            // Address2 = Address2 + long_name + ", ";
                            City = long_name;
                        } else if (Type.equalsIgnoreCase("administrative_area_level_2")) {
                            County = long_name;
                        } else if (Type.equalsIgnoreCase("administrative_area_level_1")) {
                            State = long_name;
                        } else if (Type.equalsIgnoreCase("country")) {
                            Country = long_name;
                        } else if (Type.equalsIgnoreCase("postal_code")) {
                            PIN = long_name;
                        }
                    }

                    // JSONArray mtypes = zero2.getJSONArray("types");
                    // String Type = mtypes.getString(0);
                    // Log.e(Type,long_name);
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public String getAddress1() {
        return Address1;

    }

    public String getAddress2() {
        return Address2;

    }

    public String getCity() {
        return City;

    }

    public String getState() {
        return State;

    }

    public String getCountry() {
        return Country;

    }

    public String getCounty() {
        return County;

    }

    public String getPIN() {
        return PIN;

    }

}

JSON PARSER CLASS

public class parser_Json {
    public static JSONObject getJSONfromURL(String url) {

        // initialize
        InputStream is = null;
        String result = "";
        JSONObject jObject = null;

        // http post
        try {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(url);
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            is = entity.getContent();

        } catch (Exception e) {
            Log.e("log_tag", "Error in http connection " + e.toString());
        }

        // convert response to string
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            result = sb.toString();
        } catch (Exception e) {
            Log.e("log_tag", "Error converting result " + e.toString());
        }

        // try parse the string to a JSON object
        try {
            jObject = new JSONObject(result);
        } catch (JSONException e) {
            Log.e("log_tag", "Error parsing data " + e.toString());
        }

        return jObject;
    }

}

Get the particular address using latitude and longitude, From a Geocoder object, you can call the getFromLocation(double, double, int) method. like :- private String getAddress(double latitude, double longitude)  Latlong.net is an online geographic tool that can be used to lookup latitude and longitude of a place, and get its coordinates on map. You can search for a place using a city's or town's name, as well as the name of special places, and the correct lat long coordinates will be shown at the bottom of the latitude longitude finder form. At that, the place you found will be displayed with the point marker centered on map.

    String longti = "0";
    String lati = "0";
    LocationManager locationManager;

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
                locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
                        1000, 1, new MyLocationListners());

    final Location location = locationManager
                    .getLastKnownLocation(LocationManager.GPS_PROVIDER); 

//these are your longtitude and latitude  
         lati = String.valueOf(location.getLatitude());  
         longti = String.valueOf(location.getLongitude());

//here we are getting the address using the geo codes(longtitude and latitude). 

 String ad = getAddress(location.getLatitude(),location.getLongitude());


    private String getAddress(double LATITUDE, double LONGITUDE) {
        String strAdd = "";
        Geocoder geocoder = new Geocoder(this, Locale.getDefault());
        try {
            List<Address> addresses = geocoder.getFromLocation(LATITUDE,
                    LONGITUDE, 1);
            if (addresses != null) {
                Address returnedAddress = addresses.get(0);
                StringBuilder strReturnedAddress = new StringBuilder("");

                for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) {
                    strReturnedAddress
                            .append(returnedAddress.getAddressLine(i)).append(
                                    "\n");
                }
                strAdd = strReturnedAddress.toString();
                Log.w("My Current loction address",
                        "" + strReturnedAddress.toString());
            } else {
                Log.w("My Current loction address", "No Address returned!");
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.w("My Current loction address", "Canont get Address!");
        }
        return strAdd;
    }

public class MyLocationListners implements LocationListener {

        @Override
        public void onLocationChanged(Location location) {
        }

        @Override
        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }

    }

//make sure the gps and internet are on //also sometimes, the location wont be visible at first time you run the code due to some //google services problem so you must restart the phone //hope this helps you

Find or enter latitude & longitude - Computer, You can search for a place using its latitude and longitude GPS coordinates. and latitude, you can use plus codes to share a place without an address. Mouse Hover Lat Long This free online Address Finder tool helps to find the location by latitude and longitude. Just enter the latitude and longitude, and this Address Finder tool will provide the address based on the given latitude and longitude. Also, you can see an Google Map is displayed under the Lat Long to Address Converter tool.

I have tried to modify the class given by Vipul Purohit answer to make it better

public class ReverseGeoCoding {
private String address1, address2, city, state, country, county, PIN;
private static final String LOG_TAG = ReverseGeoCoding.class.getSimpleName();

public ReverseGeoCoding(double latitude, double longitude) {
    init();
    retrieveData(latitude, longitude);
}

private void retrieveData(double latitude, double longitude) {
    try {
        String responseFromHttpUrl = getResponseFromHttpUrl(buildUrl(latitude, longitude));
        JSONObject jsonResponse = new JSONObject(responseFromHttpUrl);
        String status = jsonResponse.getString("status");
        if (status.equalsIgnoreCase("OK")) {
            JSONArray results = jsonResponse.getJSONArray("results");
            JSONObject zero = results.getJSONObject(0);
            JSONArray addressComponents = zero.getJSONArray("address_components");

            for (int i = 0; i < addressComponents.length(); i++) {
                JSONObject zero2 = addressComponents.getJSONObject(i);
                String longName = zero2.getString("long_name");
                JSONArray types = zero2.getJSONArray("types");
                String type = types.getString(0);


                if (!TextUtils.isEmpty(longName)) {
                    if (type.equalsIgnoreCase("street_number")) {
                        address1 = longName + " ";
                    } else if (type.equalsIgnoreCase("route")) {
                        address1 = address1 + longName;
                    } else if (type.equalsIgnoreCase("sublocality")) {
                        address2 = longName;
                    } else if (type.equalsIgnoreCase("locality")) {
                        // address2 = address2 + longName + ", ";
                        city = longName;
                    } else if (type.equalsIgnoreCase("administrative_area_level_2")) {
                        county = longName;
                    } else if (type.equalsIgnoreCase("administrative_area_level_1")) {
                        state = longName;
                    } else if (type.equalsIgnoreCase("country")) {
                        country = longName;
                    } else if (type.equalsIgnoreCase("postal_code")) {
                        PIN = longName;
                    }
                }
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

private void init() {
    address1 = "";
    address2 = "";
    city = "";
    state = "";
    country = "";
    county = "";
    PIN = "";
}

private URL buildUrl(double latitude, double longitude) {
    Uri uri = Uri.parse("http://maps.googleapis.com/maps/api/geocode/json").buildUpon()
            .appendQueryParameter("latlng", latitude + "," + longitude)
            .build();
    try {
        return new URL(uri.toString());
    } catch (MalformedURLException e) {
        e.printStackTrace();
        Log.e(LOG_TAG, "can't construct location object");
        return null;
    }
}

private String getResponseFromHttpUrl(URL url) throws IOException {
    HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
    try {
        InputStream in = urlConnection.getInputStream();
        Scanner scanner = new Scanner(in);
        scanner.useDelimiter("\\A");
        if (scanner.hasNext()) {
            return scanner.next();
        } else {
            return null;
        }
    } finally {
        urlConnection.disconnect();
    }
}

public String getAddress1() { return address1; }

public String getAddress2() { return address2; }

public String getCity() { return city; }

public String getState() { return state; }

public String getCountry() { return country; }

public String getCounty() { return county; }

public String getPIN() { return PIN; }

}

Latitude & Longitude to Address Tool, Use the Latitude and Longitude to address converter to find any U.S. address from a given coordinate. Longitude must be a negative number. Displays a map with  Find the latitude and longitude coordinates of a location by entering it into the address field and typing return or clicking the "find" button. To find the GPS coordinates of several locations use the Batch Geocode page.

so many gave so many answer but all missed out the most crucial part.Below is how i achieved this: You need an API Key. https://developers.google.com/maps/documentation/android-api/signup Just take time patiently go through the code.I used the inner class in fragment. code:-

private class DownloadRawData extends AsyncTask<LatLng, Void, ArrayList<String>> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
              progressDialog=new ProgressDialog(getActivity());
            progressDialog.setMessage("Loading........");
            progressDialog.setCancelable(false);
            progressDialog.show();
        }


        @Override
        protected ArrayList<String> doInBackground(LatLng... latLng) {
            ArrayList<String> strings=retrieveData(latLng[0].latitude,latLng[0].longitude);
            return strings;
        }

        @Override
        protected void onPostExecute(ArrayList<String> s) {
            super.onPostExecute(s);
            if(progressDialog!=null)
            progressDialog.dismiss();
            LocationInfoDialog locationinfoDialog=new LocationInfoDialog(getActivity(),s);
            locationinfoDialog.show();
            locationinfoDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            locationinfoDialog.setCancelable(false);
        }
    }

    private void init() {
        address1 = "";
        address2 = "";
        city = "";
        state = "";
        country = "";
        county = "";
        PIN = "";
    }
    private String createUrl(double latitude, double longitude) throws UnsupportedEncodingException {
        init();
        return "https://maps.googleapis.com/maps/api/geocode/json?" + "latlng=" + latitude + "," + longitude + "&key=" + getActivity().getResources().getString(R.string.map_apiid);
    }

    private URL buildUrl(double latitude, double longitude) {

        try {
            Log.w(TAG, "buildUrl: "+createUrl(latitude,longitude));
            return new URL(createUrl(latitude,longitude));
        } catch (MalformedURLException e) {
            e.printStackTrace();
            Log.e(LOG_TAG, "can't construct location object");
            return null;
        }
        catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }

    private String getResponseFromHttpUrl(URL url) throws IOException {
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        try {
            InputStream in = urlConnection.getInputStream();
            Scanner scanner = new Scanner(in);
            scanner.useDelimiter("\\A");
            if (scanner.hasNext()) {
                return scanner.next();
            } else {
                return null;
            }
        } finally {
            urlConnection.disconnect();
        }
    }

    public String getAddress1() { return address1; }

    public String getAddress2() { return address2; }

    public String getCity() { return city; }

    public String getState() { return state; }

    public String getCountry() { return country; }

    public String getCounty() { return county; }

    public String getPIN() { return PIN; }
    private ArrayList<String> retrieveData(double latitude, double longitude) {
        ArrayList<String> strings=new ArrayList<>();
        try {
            String responseFromHttpUrl = getResponseFromHttpUrl(buildUrl(latitude, longitude));
            JSONObject jsonResponse = new JSONObject(responseFromHttpUrl);
            String status = jsonResponse.getString("status");
            if (status.equalsIgnoreCase("OK")) {
                JSONArray results = jsonResponse.getJSONArray("results");
                JSONObject zero = results.getJSONObject(0);
                JSONArray addressComponents = zero.getJSONArray("address_components");
                String formatadd= zero.getString("formatted_address");

                for (int i = 0; i < addressComponents.length(); i++) {
                    JSONObject zero2 = addressComponents.getJSONObject(i);
                    String longName = zero2.getString("long_name");
                    JSONArray types = zero2.getJSONArray("types");
                    String type = types.getString(0);


                    if (!TextUtils.isEmpty(longName)) {
                        if (type.equalsIgnoreCase("street_number")) {
                            address1 = longName + " ";

                        } else if (type.equalsIgnoreCase("route")) {
                            address1 = address1 + longName;
                        } else if (type.equalsIgnoreCase("sublocality")) {
                            address2 = longName;
                        } else if (type.equalsIgnoreCase("locality")) {
                            // address2 = address2 + longName + ", ";
                            city = longName;
                        } else if (type.equalsIgnoreCase("administrative_area_level_2")) {
                            county = longName;
                        } else if (type.equalsIgnoreCase("administrative_area_level_1")) {
                            state = longName;
                        } else if (type.equalsIgnoreCase("country")) {
                            country = longName;
                        } else if (type.equalsIgnoreCase("postal_code")) {
                            PIN = longName;
                        }
                    }
                }
                strings.add(formatadd);
                strings.add(address1);
                strings.add(address2);
                strings.add(city);
                strings.add(county);
                strings.add(state);
                strings.add(country);

                strings.add(PIN);


            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return  strings;
    }
Initialized like this:-
googleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
            @Override
            public void onMapClick(LatLng latLng) {
                markerOptions.position(latLng);

                // Setting the title for the marker.
                // This will be displayed on taping the marker
                markerOptions.title(latLng.latitude + " : " + latLng.longitude);
                googleMap.addMarker(markerOptions);
                new DownloadRawData().execute(latLng);
            }
        });

Geocode Finder, You can also click directly on the map to find the latitude and longitude of that location along with the city, state, zipcode, and address of the location. Go to gps coordinates converter, type in the lat and long coordinates and click on the Get Address button to find address from my latitude and longitude coordinates. Convert any address using the sexagesimal GPS coordinates by clicking on the Get Address button on the coordinates converter page.

GPS Coordinates, GPS Coordinates - Latitude and Longitude Finder to find GPS coordinates, my address, current latitude longitude. Get my coordinates and find lat long on map  You can click on the map to change the marker location and get the latitude longitude of the places located close to the mentioned address. This geo process is also known as geocode address.

Converting Addresses to/from Latitude/Longitude/Altitude in One , You can also use the Geocoding API to find the address for a given place ID. no known types for the particular address component, for example, Lieu-dit in France. The bounds parameter defines the latitude/longitude coordinates of the​  Reverse geocoding is the process to convert the latitude and longitude coordinates to a readable address. Type the lat long coordinates and press Convert button. Reverse geocoded address will shown below. Also the municipality, subdivision and country name can be found.

Developer Guide | Geocoding API, You can also use the geocoder to find the address for a given place ID. If too many requests are made within a certain time period, the API returns an you should use reverse geocoding, passing the latitude/longitude of the address as a​  Making call to Google Geocoding API to fetch Co-ordinates (Latitude and Longitude) of an Address Location in ASP.Net The following click event handler is executed when the Search Button is clicked, the address from the TextBox is passed to the Google Geocoding API Service using WebRequest.

Comments
  • developer.android.com/reference/android/location/Geocoder.html
  • possible dublicate stackoverflow.com/questions/2296377/…
  • You replace sensor with key=API_KEY.It will work
  • Possible duplicate of How to get complete address from latitude and longitude?
  • thanks using the above code can i get the exact address location
  • let me check, +1 for your help
  • It doesn't work, address always empty, no errors, no exception, only empty.
  • The curLongitude is not being recognized. Is there a way I can solve it?
  • Just pass your latitude and longitude at the place of Global.curLongitude and Global.curLatitude.
  • thank you very much but I am getting this errors in logcat 02-26 16:48:21.900 31246-31246/guide_me_for_all.guide_me_for_all E/log_tag﹕ Error in http connection android.os.NetworkOnMainThreadException 02-26 16:48:21.900 31246-31246/guide_me_for_all.guide_me_for_all E/log_tag﹕ Error converting result java.lang.NullPointerException: lock == null 02-26 16:48:21.910 31246-31246/guide_me_for_all.guide_me_for_all E/log_tag﹕ Error parsing data org.json.JSONException: End of input at character 0 of and a null pointer exception in this if (Status.equalsIgnoreCase("OK")) {.
  • This exception is thrown when an application attempts to perform a networking operation on its main thread.Try to run your code in AsyncTask. See this link for more detail link
  • Awesomesauce kiddo
  • modified your answer.Check above