Get latitude and longitude based on city, zip code or street

In my current Android app, I would like to get the geocoordinates based on the entered city name, street name or zip code. How can i do this?

Best regards, Roni

+3
source share
4 answers

Mark the method Geocoder.getFromLocationName(cityName, maxResults).

Use it as follows:

List<Address> addressList = geoCoder.getFromLocationName(cityName, 1);
Address address = addressList.get(0);
if(address.hasLatitude() && address.hasLongitude()){
    double selectedLat = address.getLatitude();
    double selectedLng = address.getLongitude();
}
+6
source

Hi, try the following code to get the geocoding point from the given address.

List<Address> foundGeocode = null;
/* find the addresses  by using getFromLocationName() method with the given address*/
foundGeocode = new Geocoder(this).getFromLocationName("address here", 1);
 foundGeocode.get(0).getLatitude(); //getting latitude
 foundGeocode.get(0).getLongitude();//getting longitude
+5
source

,

, World Gazetteer, , ( )

http://www.world-gazetteer.com/home.htm

:

other statistics ..... various statistics: tables, maps and downloadable data

and from the page that appears, click on the link that reads:

popdata (1.4 MB)

Unzip the file and you get it!

Database is a free database of master cities in the world, including latitude, longitude and population data ... etc ..

Get it from: http://answers.google.com/answers/threadview?id=432778

+1
source

Try it.

Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());
try {
    List<Address> addresses = geoCoder.getFromLocation(latitude , longitude, 1);

    String strCompleteAddress= "";
    //if (addresses.size() > 0)
    //{
        for (int i=0; i<addresses.get(0).getMaxAddressLineIndex();i++)
            strCompleteAddress+= addresses.get(0).getAddressLine(i) + "\n";
    // }
    Log.i("MyLocTAG => ", strCompleteAddress);
    Toast.makeText(getBaseContext(), strCompleteAddress, Toast.LENGTH_LONG).show();
}
catch (IOException e) {
    Log.i("MyLocTAG => ", "this is the exception part");
    e.printStackTrace();
}
0
source

Source: https://habr.com/ru/post/1786837/


All Articles