谷歌地图:如何在Android中获取地址

Akh*_*hil 4 android google-maps

当我点击特定地址时,如何从谷歌地图获取位置或地址.是否可以使用地图叠加从地图视图中收集地址.

Dip*_*iya 10

请使用以下代码获取地址.

try {
    Geocoder geo = new Geocoder(youractivityclassname.this.getApplicationContext(), Locale.getDefault());
    List<Address> addresses = geo.getFromLocation(latitude, longitude, 1);
    if (addresses.isEmpty()) {
        yourtextfieldname.setText("Waiting for Location");
    }
    else {
        if (addresses.size() > 0) {
            yourtextfieldname.setText(addresses.get(0).getFeatureName() + ", " + addresses.get(0).getLocality() +", " + addresses.get(0).getAdminArea() + ", " + addresses.get(0).getCountryName());
            //Toast.makeText(getApplicationContext(), "Address:- " + addresses.get(0).getFeatureName() + addresses.get(0).getAdminArea() + addresses.get(0).getLocality(), Toast.LENGTH_LONG).show();
        }
    }
}
catch (Exception e) {
    e.printStackTrace(); // getFromLocation() may sometimes fail
}
Run Code Online (Sandbox Code Playgroud)

有关更多信息和完整示例,请参阅以下链接.

在Android中使用Google地图