开发者

How to display Current Location ADDRESS in textbox? [closed]

开发者 https://www.devze.com 2023-04-06 06:39 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, v开发者_如何学Goague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form.
It's difficult to tell what is being asked here. This question is ambiguous, v开发者_如何学Goague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I've created this Textbox, and a Button beside it. I've also linked this Button to a class which display a map with the longitude, latitude, a push pin etc. But i have a question, how do i make this textbox such that it auto generate the current location address ?


hiii..

It's so simple if you already tracked the latitude and longitude of as in case of map view.

TextView myAddress = (TextView)findViewById(R.id.myaddress);

       myLatitude.setText("Latitude: " + String.valueOf(LATITUDE));
       myLongitude.setText("Longitude: " + String.valueOf(LONGITUDE));

       Geocoder geocoder = new Geocoder(this, Locale.ENGLISH);

       try {
  List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1);

  if(addresses != null) {
   Address returnedAddress = addresses.get(0);
   StringBuilder strReturnedAddress = new StringBuilder("Address:\n");
   for(int i=0; i<returnedAddress.getMaxAddressLineIndex(); i++) {
    strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
   }
   myAddress.setText(strReturnedAddress.toString());
  }
  else{
   myAddress.setText("No Address returned!");
  }
 } catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  myAddress.setText("Canont get Address!");
 }

   }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消