Get location name from fetched coordinates

前端 未结 3 839
死守一世寂寞
死守一世寂寞 2020-12-02 18:02

What i have: currently my app is only telling me the coordinates of my current location.

What i want: Get location name from coordi

3条回答
  •  伪装坚强ぢ
    2020-12-02 18:17

    Here i am given a single just pass the latitude and longitude in this function then you got all the information related to this latitude and longitude.

    public void getAddress(double lat, double lng) {
        Geocoder geocoder = new Geocoder(HomeActivity.mContext, Locale.getDefault());
        try {
            List
    addresses = geocoder.getFromLocation(lat, lng, 1); Address obj = addresses.get(0); String add = obj.getAddressLine(0); GUIStatics.currentAddress = obj.getSubAdminArea() + "," + obj.getAdminArea(); GUIStatics.latitude = obj.getLatitude(); GUIStatics.longitude = obj.getLongitude(); GUIStatics.currentCity= obj.getSubAdminArea(); GUIStatics.currentState= obj.getAdminArea(); add = add + "\n" + obj.getCountryName(); add = add + "\n" + obj.getCountryCode(); add = add + "\n" + obj.getAdminArea(); add = add + "\n" + obj.getPostalCode(); add = add + "\n" + obj.getSubAdminArea(); add = add + "\n" + obj.getLocality(); add = add + "\n" + obj.getSubThoroughfare(); Log.v("IGA", "Address" + add); // Toast.makeText(this, "Address=>" + add, // Toast.LENGTH_SHORT).show(); // TennisAppActivity.showDialog(add); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); } }

    I hope you get the solution to your answer.

提交回复
热议问题