我正在两个 Activity 之间传递数据。我想这样做:当用户长按 map 时,新的 InfoActivity 窗口将打开,显示纬度、经度和长按所在的城市。
我已经过了经纬度,但还是被城市部分困住了。
@Override
public void onMapLongClick(LatLng arg0) {
Intent intent = new Intent(getActivity(), InfoActivity.class);
intent.putExtra("latitude", arg0.latitude);
intent.putExtra("longitude", arg0.longitude);
startActivity(intent);
}
我如何获取长按 map 的城市并将其添加到我的 InfoActivity。
感谢任何帮助:)
最佳答案
How would I get the city where the map is long clicked
使用Geocoder带有 arg0
的类,用于获取长按 map 的城市。例如:
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> allAddresses = geocoder.getFromLocation(
arg0.latitude, arg0.longitude, 1);
现在从 allAddresses
获取长按点所需的所有详细信息。
and add pass it to my InfoActivity
要在两个 Activity 之间传递字符串,请参阅以下帖子:
关于java - 在 Android 中长按显示城市,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38324210/