get latitude and longitude from city name

后端 未结 3 1259
面向向阳花
面向向阳花 2020-12-16 07:07

In my current android application, I would like to get the geocordinates based on an entered city name, street name or zip code. How can I accomplish this?

Best Rega

3条回答
  •  醉梦人生
    2020-12-16 07:46

    searchedAddress --> Can be (city name/address/Zipcode).

    public boolean getLatitudeAndLongitudeFromGoogleMapForAddress(String searchedAddress){
    
        Geocoder coder = new Geocoder(IPlant.iPlantActivity);
        List
    address; try { address = coder.getFromLocationName(searchedAddress,5); if (address == null) { Log.d(TAG, "############Address not correct #########"); } Address location = address.get(0); Log.d(TAG, "Address Latitude : "+ location.getLatitude();+ "Address Longitude : "+ location.getLongitude()); return true; } catch(Exception e) { Log.d(TAG, "MY_ERROR : ############Address Not Found"); return false; } }

提交回复
热议问题