Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.kontakti;
- import android.content.Context;
- import android.location.Address;
- import android.location.Geocoder;
- import android.os.Bundle;
- import android.os.Handler;
- import android.os.Message;
- import android.util.Log;
- import java.io.IOException;
- import java.util.List;
- import java.util.Locale;
- public class GeoCodingLocation {
- private static final String TAG = "GeocodingLocation";
- public interface LatLngGet{
- void getLatLng(double lat, double lon);
- void ErrorMessage(String error);
- }
- public static void getAddressFromLocation(final String locationAddress,
- final Context context, final LatLngGet callback) {
- Thread thread = new Thread() {
- @Override
- public void run() {
- Geocoder geocoder = new Geocoder(context, Locale.getDefault());
- try {
- List<Address>
- addressList = geocoder.getFromLocationName(locationAddress, 1);
- if (addressList != null && addressList.size() > 0) {
- Address address = (Address) addressList.get(0);
- StringBuilder sb = new StringBuilder();
- sb.append(address.getLatitude()).append("\n");
- sb.append(address.getLongitude()).append("\n");
- callback.getLatLng(address.getLatitude(), address.getLongitude());
- }
- } catch (IOException e) {
- Log.e(TAG, "Unable to connect to Geocoder", e);
- callback.ErrorMessage(e.getLocalizedMessage());
- } finally {
- }
- }
- };
- thread.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement