【发布时间】:2016-11-20 15:15:24
【问题描述】:
我有一个地图活动,上面还有一个 EditText,我想在地图上有拖动时在该 EditText 中显示更改的地址。我目前正在使用 Geocoder 类根据地图提供的坐标检索地址。但是这种方式在地图的流畅拖动中造成了很大的延迟。有没有更好的方法来检索地址或更有效的方法来使用 Geocoder 类?现在,我已经在我的地图的 OnCameraChangeListener 事件中实现了 getAddress() 方法。这是代码。
mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition cameraPosition) {
double latitude=mMap.getCameraPosition().target.latitude;
double longitude=mMap.getCameraPosition().target.longitude;
String _Location="";
Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
try {
List<Address> listAddresses = geocoder.getFromLocation(latitude, longitude, 1);
if(null!=listAddresses&&listAddresses.size()>0){
_Location = listAddresses.get(0).getAddressLine(0);
}
} catch (IOException e) {
e.printStackTrace();
}
EditText addressTxt=(EditText) findViewById(R.id.search_address_txt);
addressTxt.setText(_Location);
}
});
我看到另一个应用程序实现了,其中搜索的地址位于地图拖动的末尾,并且地图的运动没有滞后。
【问题讨论】:
标签: java android google-maps google-maps-api-3