Guest User

Untitled

a guest
Dec 11th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. maPosition.setOnClickListener(new View.OnClickListener() {
  2. @Override
  3. public void onClick(View v) {
  4. Geocoder gc = new Geocoder(getActivity());
  5. getLocation();
  6. List<Address> list = null;
  7. try {
  8. list = gc.getFromLocation(lat, lng, 1);
  9. if (list!= null) {
  10. Address returnedAddress = list.get(0);
  11. start_address.setText(returnedAddress.getAddressLine(0) + ", " + returnedAddress.getPostalCode() + " " + returnedAddress.getLocality());
  12. } else {
  13. start_address.setText("No Address returned!");
  14. }
  15. } catch (IOException e) {
  16. e.printStackTrace();
  17. start_address.setText("Cannot get address");
  18. }
  19.  
  20. }
  21. });
  22.  
  23. maPosition.setOnClickListener(new View.OnClickListener() {
  24. @Override
  25. public void onClick(View v) {
  26. new Thread(new Runnable() {
  27. @Override
  28. public void run() {
  29. Geocoder gc = new Geocoder(getActivity());
  30. List<Address> list = null;
  31. try {
  32. list = gc.getFromLocation(lat, lng, 1);
  33. // start_address.setText(Double.toString(lat));
  34. if(list!= null && !list.isEmpty()) {
  35. Address returnedAddress = list.get(0);
  36. StringBuilder adressBuilder = new StringBuilder();
  37. adressBuilder.append(returnedAddress.getAddressLine(0) + ", " + returnedAddress.getPostalCode() + " " + returnedAddress.getLocality());
  38. getActivity().runOnUiThread(new Runnable() {
  39. @Override
  40. public void run() {
  41. start_address.setText("No Address returned!");
  42. }
  43. //job done on the UI thread
  44. });
  45. }
  46. else{
  47. getActivity().runOnUiThread(new Runnable() {
  48. @Override
  49. public void run() {
  50. start_address.setText("No Address returned!");
  51. }
  52. //job done on the UI thread
  53. });
  54. }
  55. } catch (IOException e) {
  56. e.printStackTrace();
  57. }
  58. }
  59. }).start();
  60.  
  61. }
  62. });
  63.  
  64. list = gc.getFromLocation(lat, lng, 1);
  65. if (list != null && !list.isEmpty()) {
  66. Address returnedAddress = list.get(0);
  67. //...
  68.  
  69. new Thread(new Runnable() {
  70. public void run() {
  71. //job done on a background thread, e.g. getFromLocation() call
  72. }
  73. }).start();
  74.  
  75. getActivity().runOnUiThread(new Runnable() {
  76. //job done on the UI thread
  77. });
Add Comment
Please, Sign In to add comment