0

我正在使用Emulator Google api(Google 公司)。我想获取给予者地理点的地址。但我收到此“服务不可用”错误。我目前处于 api 级别 10。有人告诉我关于模拟器上的这个错误。但我不认为它在我的模拟器上,因为内置的地图应用程序运行良好。

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

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();
                }
4

1 回答 1

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;
    }
于 2013-02-01T11:44:11.117 回答