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
Check out the method Geocoder.getFromLocationName(cityName, maxResults).
Use it like this:
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();
}
Hi try the following code to get Geocode point from 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
Hi,
There's a very nice site called the World Gazetteer that has the data you need, in a neat, downloadable file (by city name)
http://www.world-gazetteer.com/home.htm
From the main page, click on the link that says:
other statistics.....various statistics: tables, maps and downloadable data
and from the page that comes up, click on the link that says:
popdata (1.4 MB)
Unzip the file, and you got it!
The database is free master database of world cities which includes latitude, longitude, and population data...etc.
Got this from: http://answers.google.com/answers/threadview?id=432778
Try this.
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();
}