【问题标题】:google map: how to get address in android谷歌地图:如何在android中获取地址
【发布时间】:2012-11-28 05:49:51
【问题描述】:

当我单击特定地址时,如何从谷歌地图获取位置或地址。是否可以使用地图覆盖从地图视图中收集地址。

【问题讨论】:

标签: android google-maps


【解决方案1】:

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

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
}

有关更多信息和完整示例,请参见下面的链接。

Using Google Maps in Android

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多