Java 在Android中长时间点击显示城市

Java 在Android中长时间点击显示城市,java,android,google-maps,google-maps-markers,Java,Android,Google Maps,Google Maps Markers,我在两个活动之间传递数据。我想这样做:当用户长时间点击地图时,新的InfoActivity窗口打开,显示纬度、经度和长时间点击的城市 我已经通过了拉特和朗,但被困在城市部分 @Override public void onMapLongClick(LatLng arg0) { Intent intent = new Intent(getActivity(), InfoActivity.class); int

我在两个活动之间传递数据。我想这样做:当用户长时间点击地图时,新的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);

        }
如何获取地图被长时间点击的城市并将其添加到我的InfoActivity中

感谢您的帮助:)

我怎样才能找到地图被长时间点击的城市

使用带有
arg0
的类来获取长时间单击地图的城市。例如:

 Geocoder geocoder = new Geocoder(this, Locale.getDefault());
 List<Address> allAddresses = geocoder.getFromLocation(
                               arg0.latitude, arg0.longitude, 1);
Geocoder-Geocoder=new-Geocoder(这个,Locale.getDefault());
名单

我怎样才能找到地图被长时间点击的城市

使用带有
arg0
的类来获取长时间单击地图的城市。例如:

 Geocoder geocoder = new Geocoder(this, Locale.getDefault());
 List<Address> allAddresses = geocoder.getFromLocation(
                               arg0.latitude, arg0.longitude, 1);
Geocoder-Geocoder=new-Geocoder(这个,Locale.getDefault());

列表

您始终可以使用地理编码器:

Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(arg0.latitude, arg0.longitude, 1);
String cityName = addresses.get(0).getAddressLine(0);
Geocoder-Geocoder=new-Geocoder(这个,Locale.getDefault());
列表地址=geocoder.getFromLocation(arg0.latitude,arg0.longitude,1);
字符串cityName=addresses.get(0).getAddressLine(0);

您可以随时使用地理编码器:

Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(arg0.latitude, arg0.longitude, 1);
String cityName = addresses.get(0).getAddressLine(0);
Geocoder-Geocoder=new-Geocoder(这个,Locale.getDefault());
列表地址=geocoder.getFromLocation(arg0.latitude,arg0.longitude,1);
字符串cityName=addresses.get(0).getAddressLine(0);

你可能想在谷歌上搜索“反向地理编码”。@Gerald Schenider可以。谢谢。你可能想在谷歌上搜索“反向地理编码”。@Gerald Schenider可以。谢谢。我试着把这个代码块放在我的onMapLongClick中,但是对于
Geocoder-Geocoder=new-Geocoder(这个,Locale.getDefault()),我得到了以下错误:
-geocoder中的geocoder(android.content.context,Locale)不能应用于(anonymous com.google.android.gms.maps.android maps.onmaplongclicklistener)@Kemo:使用当前的活动上下文,而不是
类似于如果您正在使用活动,则使用
您的活动名称。此
或如果使用片段,则使用
getActivity()
而不是
getActivity()有效。我还有另一个错误-在
geocoder.getFromLocation(arg0.latitude,arg0.longitude,1)中
获取此错误-未处理的异常java.ioexception,即使我尝试过:
尝试{ArrayList alladdress=geocoder.getFromLocation(arg0.latitude,arg0.longitude,1);}catch(ioexception e){e.printStackTrace();}
如果没有try/catch,我会得到未处理的异常java.ioexception,而使用try/catch,我会得到不兼容的类型-required java.util.arrayList找到java.util.array@Kemo:Use
List
而不是
arrayList
我尝试将此代码块放在onMapLongClick中,但是对于
Geocoder Geocoder=newgeocoder(这个,Locale.getDefault()),我得到了以下错误:
-geocoder中的geocoder(android.content.context,Locale)不能应用于(anonymous com.google.android.gms.maps.android maps.onmaplongclicklistener)@Kemo:使用当前的活动上下文,而不是
类似于如果您正在使用活动,则使用
您的活动名称。此
或如果使用片段,则使用
getActivity()
而不是
getActivity()有效。我还有另一个错误-在
geocoder.getFromLocation(arg0.latitude,arg0.longitude,1)中
获取此错误-未处理的异常java.ioexception,即使我尝试过:
尝试{ArrayList alladdress=geocoder.getFromLocation(arg0.latitude,arg0.longitude,1);}catch(ioexception e){e.printStackTrace();}
如果没有try/catch,我会得到未处理的异常java.ioexception,如果使用try/catch,我会得到不兼容的类型-required java.util.arrayList find java.util.array@Kemo:使用
List
而不是
arrayList