1

I am a newbie of programming Android with Google map API. I met a question about the capturing the target country, when the users click any point of the target country (e.g. US as below figure showed), how can I get the value "United States" on this onClick action??

Thanks for any comments or suggestion of my dumb question.

enter image description here

Chris.C
  • 297
  • 3
  • 17
  • See this question on using Google's reverse geocoding API: http://stackoverflow.com/questions/4013606/google-maps-how-to-get-country-state-province-region-city-given-a-lat-long-va – csander Aug 17 '16 at 03:50

1 Answers1

1

when user click onmap there is a listener called onMapClickListener()

googleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
    @Override
    public void onMapClick(LatLng position) {
           //Get the lat long here from variable position
           //Use GeoCoder class to fetch the country from latlong like this
           Geocoder geocoder = new Geocoder(getActivity(), Locale.getDefault()); 
           List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);         
           if(addresses.size() > 0){
               String country = addresses.get(0).getCountryName();
           }
    }
});
Rahul
  • 1,380
  • 1
  • 10
  • 24
  • Sorry for the late reply. Do I need to import any statement at the Import part for using GoogleMap.OnMapClickListener? Thanks. – Chris.C Aug 19 '16 at 03:09