user3538102
user3538102

Reputation: 171

reverse geocoding coordinates to address

I have created the code that returns me the full address of my current location but I want it to just return certain aspects of my current position e.g. just the postcode, just the county etc.

              //Place your latitude and longitude
              List<Address> addresses = geocoder.getFromLocation(lati,longi, 1);

              if(addresses != null) {

                  Address fetchedAddress = addresses.get(0);
                  StringBuilder strAddress = new StringBuilder();

                  for(int i=0; i<fetchedAddress.getMaxAddressLineIndex(); i++) {
                        strAddress.append(fetchedAddress.getAddressLine(i)).append("\n");
                  }

                 String Address= strAddress.toString();

                 Toast.makeText(getApplicationContext(),Address, Toast.LENGTH_LONG).show();

That is the code I have so far so it would be greatly appreciated if someone could point me in the direction to a tutorial or even give me help with this issue

Upvotes: 1

Views: 562

Answers (1)

DarkLeafyGreen
DarkLeafyGreen

Reputation: 70466

You already got everything in place. Query the address object for information:

fetchedAddress.getPostalCode() //zipcode
fetchedAddress.getLocality() //city

See http://developer.android.com/reference/android/location/Address.html

Upvotes: 1

Related Questions