如何在地图中获取微区地址

时间:2018-07-14 18:55:13

标签: android google-maps-android-api-2 google-geocoder

我有一个地点选择器,可以根据座标给我地址。问题是,某些地区有微区,我无法获得微区名称或街道地址。

这是我的代码:

private GoogleMap mMap;
private GoogleMap.OnCameraIdleListener onCameraIdleListener;
private TextView resutText;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    resutText = (TextView) findViewById(R.id.dragg_result);
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
    configureCameraIdle();
}
private void configureCameraIdle() {
    onCameraIdleListener = new GoogleMap.OnCameraIdleListener() {
        @Override
        public void onCameraIdle() {
            LatLng latLng = mMap.getCameraPosition().target;
            Geocoder geocoder = new Geocoder(MapsActivity.this, Locale.getDefault());
            try {
                List<Address> addressList = geocoder.getFromLocation(latLng.latitude, latLng.longitude, 1);
                if (addressList != null && addressList.size() > 0) {
                    String address = addressList.get(0).getThoroughfare();
                    String number = addressList.get(0).getFeatureName();
                    resutText.setText(address + "  " + number + "\n"+addressList);                    }

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    };
}

这就是我得到的: enter image description here

有什么办法可以解决这个问题?

0 个答案:

没有答案