Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.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获取城市名称_Android_Google Geocoder_Gmsplacepicker - Fatal编程技术网

有没有办法为谷歌地点选择器android获取城市名称

有没有办法为谷歌地点选择器android获取城市名称,android,google-geocoder,gmsplacepicker,Android,Google Geocoder,Gmsplacepicker,我正试图从谷歌地点选择器中获取城市名称。是否有任何方法可以使用地点选择器API获取城市名称。我知道我们不能简单地通过放置place.getCity()从API获取它import android.location.address;好的,我确实更改了。但当我尝试在文本视图中设置它时,给出了非常奇怪的值感谢您的帮助Nancy。我刚刚添加了city.setText(String.valueOf(addresses.get(0.getLocation());

我正试图从谷歌地点选择器中获取城市名称。是否有任何方法可以使用地点选择器API获取城市名称。我知道我们不能简单地通过放置
place.getCity()从API获取它
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if(requestCode == REQUEST_PLACE_PICKER){

            if(resultCode==RESULT_OK){

                Place place = PlacePicker.getPlace(data,this);

                final CharSequence name = place.getName();
                final CharSequence address = place.getAddress();
                final CharSequence phone = place.getPhoneNumber();
                final String placeId = place.getId();
                final LatLng latLng = place.getLatLng();

                if(place.getLocale() != null) {
                    String aname = place.getLocale().toString();
                    areaname.setText(aname);
                }

                location.setText(address);
                gname.setText(name);
                latlon.setText(String.valueOf(latLng));

            }
        }
    }
我不希望城市中有任何空值。我读到
Geocoder
将给出大部分空值。

尝试使用Geocoder

final Place place = PlacePicker.getPlace(this,data);
Geocoder geocoder = new Geocoder(this);
try
{
    List<Address> addresses = geocoder.getFromLocation(place.getLatLng().latitude,place.getLatLng().longitude, 1);
    String address = addresses.get(0).getAddressLine(0);
    String city = addresses.get(0).getAddressLine(1);
    //String country = addresses.get(0).getAddressLine(2);  

} catch (IOException e)
{

    e.printStackTrace();
}
final Place=PlacePicker.getPlace(这个,数据);
Geocoder Geocoder=新的Geocoder(本);
尝试
{
名单


错误:将地址类型更改为java.util.Listimport java.util.List;For address>import android.location.address;好的,我确实更改了。但当我尝试在文本视图中设置它时,给出了非常奇怪的值感谢您的帮助Nancy。我刚刚添加了city.setText(String.valueOf(addresses.get(0.getLocation());