地理编码服务不可用

时间:2013-02-01 11:25:39

标签: android google-maps reverse-geocoding

我正在使用 Emulator Google api's (Google inc)。我想获得给予者地址的地址。 但我得到这个“服务不可用”错误。我目前在api 10级。有人告诉我关于模拟器上的这个bug。但我不认为它在我的模拟器上,因为内置的地图应用程序工作正常。

以下是我从点获取位置的代码:

GeoPoint point = mapView.getProjection().fromPixels(
                        (int) e.getX(), (int) e.getY());
                Geocoder coder = new Geocoder(GoogleMaps.this, Locale.ENGLISH);
                try {
                    List<Address> addresses = coder.getFromLocation(
                            point.getLatitudeE6() / 1E6,
                            point.getLongitudeE6() / 1E6, 1);
                    String address = "";
                    Address a = addresses.get(0);
                    Toast.makeText(GoogleMaps.this, a.getCountryName(), 300)
                            .show();
                } catch (IOException e1) {
                    Toast.makeText(GoogleMaps.this, e1.getMessage(),
                            Toast.LENGTH_LONG).show();
                }

1 个答案:

答案 0 :(得分:0)

你可以尝试这个:

private String getAddress(double LATITUDE, double LONGITUDE){
        String strAdd = "";
        Geocoder geocoder = new Geocoder(context, Locale.getDefault());
        try {
            List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1);

            if(addresses != null) {
                Address returnedAddress = addresses.get(0);
                StringBuilder strReturnedAddress = new StringBuilder("");
                for(int i=0; i<returnedAddress.getMaxAddressLineIndex(); i++) {
                    strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
                }
                strAdd = strReturnedAddress.toString();
                MLog.v("My Current loction address", ""+strReturnedAddress.toString());
            }
            else{
                MLog.v("My Current loction address", "No Address returned!");
            }
        } catch (Exception e) {
            e.printStackTrace();
            MLog.v("My Current loction address", "Canont get Address!");
        }
        return strAdd;
    }