Domanda

I am working on a android app in which i came across a situation in which i need to get the current user postcode, so i am getting the current latitude and longitude but is there any way to find the current postcode by providing latitude and longitude.

If any web service or database to provide this information is available then please let me know about it.

È stato utile?

Soluzione

If you are talking about PostalCode then, use this..

Geocoder geoCoder = new Geocoder(getApplicationContext(), Locale.getDefault());
List<Address> address = null;

if (geoCoder != null){
   try {
       address= geoCoder.getFromLocation(latPoint, lngPoint, 1);
       } catch (IOException e1) {
       // TODO Auto-generated catch block
       e1.printStackTrace();
      }
      if (address.size()> 0){
        String postCode = address.get(0).getPostalCode();
      }

With these two permission on Manifest file..

<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

Altri suggerimenti

At present the only official source of this data is the Royal Mail's Postcode Address File (PAF), which requires a licence (at some cost).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top