4

通过点击地图,我如何获得该位置的地址。在特定位置点击,我们可以收听并传递那些我们可以获得地址的坐标,但它应该可以在 android Google map v2 中工作。

4

3 回答 3

2

可以帮助您使用完整的地图操作

于 2013-08-13T12:40:38.277 回答
2

如果您有 LatLng 数据 - 这很容易。您需要使用Goecoder

    protected String doInBackground(Location... params) {
        Geocoder geocoder =
                new Geocoder(mContext, Locale.getDefault());
        // Get the current location from the input parameter list
        Location loc = params[0];
        // Create a list to contain the result address
        List<Address> addresses = null;
        try {
            /*
             * Return 1 address.
             */
            addresses = geocoder.getFromLocation(loc.getLatitude(),
                    loc.getLongitude(), 1);
        } catch (IOException e1) {
        Log.e("LocationSampleActivity",
                "IO Exception in getFromLocation()");
        e1.printStackTrace();
        return ("IO Exception trying to get address");
        } catch (IllegalArgumentException e2) {
        // Error message to post in the log
        String errorString = "Illegal arguments " +
                Double.toString(loc.getLatitude()) +
                " , " +
                Double.toString(loc.getLongitude()) +
                " passed to address service";
        Log.e("LocationSampleActivity", errorString);
        e2.printStackTrace();
        return errorString;
        }
        // If the reverse geocode returned an address
        if (addresses != null && addresses.size() > 0) {
            // Get the first address
            Address address = addresses.get(0);
            /*
             * Format the first line of address (if available),
             * city, and country name.
             */
            String addressText = String.format(
                    "%s, %s, %s",
                    // If there's a street address, add it
                    address.getMaxAddressLineIndex() > 0 ?
                            address.getAddressLine(0) : "",
                    // Locality is usually a city
                    address.getLocality(),
                    // The country of the address
                    address.getCountryName());
            // Return the text
            return addressText;
        } else {
            return "No address found";
        }
    }
    ...
}
...

}

最好的方法是使用 AsyncTask。您可以在 Android 开发者的网站上找到完整的示例:http: //developer.android.com/training/location/display-address.html

于 2013-08-13T13:09:55.183 回答
1

您可以使用 android GeoCoder执行此操作。使用GoogleMapsv2,您可以使用 longpress获得LatLng分数。通过获取这些坐标并将它们传递给GeoCoder您可以“反向地理编码”来查找地址。

于 2013-08-13T12:33:40.390 回答