Android地理编码api可以';返回地址

Android地理编码api可以';返回地址,android,google-maps,geocoding,Android,Google Maps,Geocoding,我在地理编码位置方面遇到了一些问题,我想我已经实现了所有东西。我已经注册了一个谷歌api,我收到了一个有效的谷歌api密钥,我还打开了谷歌地图和地理编码服务,但我无法获得任何与硬编码经纬度相关的位置 代码如下: 我的AppLocationService public class AppLocationService extends Service implements LocationListener { protected LocationManager locationManager; L

我在地理编码位置方面遇到了一些问题,我想我已经实现了所有东西。我已经注册了一个谷歌api,我收到了一个有效的谷歌api密钥,我还打开了谷歌地图和地理编码服务,但我无法获得任何与硬编码经纬度相关的位置

代码如下: 我的AppLocationService

public class AppLocationService extends Service implements LocationListener {

protected LocationManager locationManager;
Location location;

private static final long MIN_DISTANCE_FOR_UPDATE = 10;
private static final long MIN_TIME_FOR_UPDATE = 1000 * 60 * 2;

public AppLocationService(Context context) {
    locationManager = (LocationManager) context
            .getSystemService(LOCATION_SERVICE);
}

public Location getLocation(String provider) {
    if (locationManager.isProviderEnabled(provider)) {
        locationManager.requestLocationUpdates(provider,
                MIN_TIME_FOR_UPDATE, MIN_DISTANCE_FOR_UPDATE, this);
        if (locationManager != null) {
            location = locationManager.getLastKnownLocation(provider);
            return location;
        }
    }
    return null;
}

@Override
public void onLocationChanged(Location location) {
}

@Override
public void onProviderDisabled(String provider) {
}

@Override
public void onProviderEnabled(String provider) {
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}

@Override
public IBinder onBind(Intent arg0) {
    return null;
}
}

我的位置地址类

public class LocationAddress {
private static final String TAG = "LocationAddress";

public static void getAddressFromLocation(final double latitude, final double longitude,
                                          final Context context, final Handler handler) {
    Thread thread = new Thread() {
        @Override
        public void run() {
            Geocoder geocoder = new Geocoder(context, Locale.getDefault());
            String result = null;
            try {
                List<Address> addressList = geocoder.getFromLocation(
                        latitude, longitude, 1);
                if (addressList != null && addressList.size() > 0) {
                    Address address = addressList.get(0);
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < address.getMaxAddressLineIndex(); i++) {
                        sb.append(address.getAddressLine(i)).append("\n");
                    }
                    sb.append(address.getLocality()).append("\n");
                    sb.append(address.getPostalCode()).append("\n");
                    sb.append(address.getCountryName());
                    result = sb.toString();
                }
            } catch (IOException e) {
                Log.e(TAG, "Unable connect to Geocoder", e);
            } finally {
                Message message = Message.obtain();
                message.setTarget(handler);
                if (result != null) {
                    message.what = 1;
                    Bundle bundle = new Bundle();
                    result = "Latitude: " + latitude + " Longitude: " + longitude +
                            "\n\nAddress:\n" + result;
                    bundle.putString("address", result);
                    message.setData(bundle);
                } else {
                    message.what = 1;
                    Bundle bundle = new Bundle();
                    result = "Latitude: " + latitude + " Longitude: " + longitude +
                            "\n Unable to get address for this lat-long.";
                    bundle.putString("address", result);
                    message.setData(bundle);
                }
                message.sendToTarget();
            }
        }
    };
    thread.start();
}

谢谢,我想你可以看看。我试过了,成功了


希望如此。

“鼓励链接到外部资源,但请在链接周围添加上下文,以便您的其他用户了解它是什么以及为什么会出现。请始终引用重要链接中最相关的部分,以防无法访问目标站点或永久脱机。”这与我复制到代码中的项目完全相同:)因此,如果它对您有效,它应该对我有效。。。我明天再检查一下。
appLocationService = new AppLocationService(
            ServerInterface.this);

    Location location = appLocationService
            .getLocation(LocationManager.GPS_PROVIDER);


    if (location != null) {
        double latitude = 47.162494;
        double longitude = 19.503304;
        LocationAddress locationAddress = new LocationAddress();
        LocationAddress.getAddressFromLocation(latitude, longitude,
                getApplicationContext(), new GeocoderHandler());
    }