Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从LatLng获取地址_Android_Location - Fatal编程技术网

Android 从LatLng获取地址

Android 从LatLng获取地址,android,location,Android,Location,目前,我正在使用以下方式在我的Android Studio MapsActivity标记中显示纬度/经度: LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude()); MarkerOptions markerOptions = new MarkerOptions(); markerOptions.position(latLng); markerOptions.title(Str

目前,我正在使用以下方式在我的Android Studio MapsActivity标记中显示纬度/经度:

 LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.position(latLng);
    markerOptions.title(String.valueOf(latLng));
    markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE));

    currentLocationMarker = mMap.addMarker((markerOptions));

    mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));

我的目标是显示整个地址。

使用地理编码器从latlng获取地址

Geocoder geocoder; 
List<Address> addresses; 
geocoder = new Geocoder(this, Locale.getDefault()); 
addresses = geocoder.getFromLocation(latitude, longitude, 1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5 
String address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
String city = addresses.get(0).getLocality();
Geocoder-Geocoder;
列出地址;
geocoder=新的geocoder(这个,Locale.getDefault());
地址=地理编码器。getFromLocation(纬度,经度,1);//这里1表示返回的最大位置结果,由它建议的1到5个文档决定
字符串地址=地址。get(0)。getAddressLine(0);//如果存在除“仅”之外的任何其他地址行,请通过getMaxAddressLineIndex()使用最大可用地址行进行检查
字符串city=addresses.get(0.getLocation();

Thank you的可能重复,我之所以发布此消息,是因为我想知道当用户位于非美国的位置时,如何更改state的“null”结果。它想在此行崩溃:String address=addresses.get(0).getAddressLine();检查地址是否为空,然后发布日志