Get country from coordinates?

后端 未结 4 1771
面向向阳花
面向向阳花 2020-12-08 03:15

How to get country name in Android, If are known geo coordinates? How to make it the simplest way?

4条回答
  •  猫巷女王i
    2020-12-08 03:40

    use this

    try {
            Geocoder geo = new Geocoder(this.getApplicationContext(), Locale.getDefault());
            List
    addresses = geo.getFromLocation(location.getLatitude(), location.getLongitude(), 1); if (addresses.isEmpty()) { placeName.setText("Waiting for Location"); } else { if (addresses.size() > 0) { placeName.setText(addresses.get(0).getFeatureName() + ", " + addresses.get(0).getLocality() +", " + addresses.get(0).getAdminArea() + ", " + addresses.get(0).getCountryName()); } } } catch(Exception e){ Toast.makeText(this, "No Location Name Found", 600).show(); }

    use this in manifest file

    
    

提交回复
热议问题