如何在谷歌地图android v2中获得地图上的城市名称ontap?
通过点击地图,我怎样才能得到那个位置的地址。在特定位置点击,我们可以听到并传递坐标,我们可以得到地址,但它应该在android谷歌地图v2中工作 你可以用安卓系统来实现这一点。使用如何在谷歌地图android v2中获得地图上的城市名称ontap?,android,google-maps,map,coordinates,android-maps-v2,Android,Google Maps,Map,Coordinates,Android Maps V2,通过点击地图,我怎样才能得到那个位置的地址。在特定位置点击,我们可以听到并传递坐标,我们可以得到地址,但它应该在android谷歌地图v2中工作 你可以用安卓系统来实现这一点。使用GoogleMapsv2,您可以获得LatLng点。通过获取这些坐标并将其传递给地理编码器,您可以“反向地理编码”来查找地址 可以帮助您使用完整的地图操作如果您有LatLng数据-这非常简单。你需要使用 受保护字符串doInBackground(位置…参数){ 地理编码器= 新的地理编码器(mContext,Local
GoogleMaps
v2,您可以获得LatLng
点。通过获取这些坐标并将其传递给地理编码器
,您可以“反向地理编码”来查找地址 可以帮助您使用完整的地图操作如果您有LatLng数据-这非常简单。你需要使用
受保护字符串doInBackground(位置…参数){
地理编码器=
新的地理编码器(mContext,Locale.getDefault());
//从输入参数列表中获取当前位置
位置loc=参数[0];
//创建包含结果地址的列表
列表到longpress示例的链接有代码。来自S/O和地理编码器示例。如果您使用google reverse geocoder或从coordinate和android获取地址,您将发现许多示例。我在应用程序中使用的相同示例获得IndexOutfound异常。我在上面的同一页中发布了代码。现在,通过添加以下行修复了错误:If(addresses!=null&&!addresses.isEmpty())如果您没有发布任何代码,我就不会捕捉到它;)很高兴你修复了它,但你尝试了什么吗?将一个标记放在水龙头上,然后读取标记的板条。这样用户可以看到其确切的点击点。感谢它工作正常:此解决方案帮助我修复了arrayIndexoutofbound异常感谢alot@adek
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";
}
}
...
}
...