通过点击地图,我如何获得该位置的地址.在特定位置点击我们可以听取并传递我们可以获得地址的那些坐标,但它应该在Android谷歌地图v2中工作.
解决方法:
如果您有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 Devlopers的网站上找到完整的示例:http://developer.android.com/training/location/display-address.html
总结以上是内存溢出为你收集整理的如何在谷歌地图android v2的地图上获取城市名称ontap?全部内容,希望文章能够帮你解决如何在谷歌地图android v2的地图上获取城市名称ontap?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)