Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- maPosition.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Geocoder gc = new Geocoder(getActivity());
- getLocation();
- List<Address> list = null;
- try {
- list = gc.getFromLocation(lat, lng, 1);
- if (list!= null) {
- Address returnedAddress = list.get(0);
- start_address.setText(returnedAddress.getAddressLine(0) + ", " + returnedAddress.getPostalCode() + " " + returnedAddress.getLocality());
- } else {
- start_address.setText("No Address returned!");
- }
- } catch (IOException e) {
- e.printStackTrace();
- start_address.setText("Cannot get address");
- }
- }
- });
- maPosition.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- Geocoder gc = new Geocoder(getActivity());
- List<Address> list = null;
- try {
- list = gc.getFromLocation(lat, lng, 1);
- // start_address.setText(Double.toString(lat));
- if(list!= null && !list.isEmpty()) {
- Address returnedAddress = list.get(0);
- StringBuilder adressBuilder = new StringBuilder();
- adressBuilder.append(returnedAddress.getAddressLine(0) + ", " + returnedAddress.getPostalCode() + " " + returnedAddress.getLocality());
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- start_address.setText("No Address returned!");
- }
- //job done on the UI thread
- });
- }
- else{
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- start_address.setText("No Address returned!");
- }
- //job done on the UI thread
- });
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }).start();
- }
- });
- list = gc.getFromLocation(lat, lng, 1);
- if (list != null && !list.isEmpty()) {
- Address returnedAddress = list.get(0);
- //...
- new Thread(new Runnable() {
- public void run() {
- //job done on a background thread, e.g. getFromLocation() call
- }
- }).start();
- getActivity().runOnUiThread(new Runnable() {
- //job done on the UI thread
- });
Add Comment
Please, Sign In to add comment