is there any way to get city name for Google Place picker android

依然范特西╮ 提交于 2019-12-04 09:48:28

Try using 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();
}

Also you can try to call webservice and parse json result to get city. Just pass the lat/ lng you get from placepicker in below url. In the result administrative_area_level_2 represents the city

http://maps.googleapis.com/maps/api/geocode/json?latlng=23,72&sensor=true

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!