ZipCode from location

Is there a way to get the zip code of the user's current location from a location of either lat or long. If so, how?

+5
source share
3 answers

Yes you can ... All you have to do is extract

http://maps.google.com/maps/geo?ll= latitude, longitude

http://maps.google.com/maps/geo?ll=10.345561,123.896932

Or try experimenting with these solutions. I can give you an idea.

Can you have a city? Using this json data, if you have a zipcode database (at maxmind.com) with this format

CountryCode | City | Zipcode


   PH | Cebu | 6000

Now query the database related to the reference code that googles returns.

UPDATE

API v2 9 2013 .

URL- API

http://maps.googleapis.com/maps/api/geocode/json?latlng=your_latitude,your_longitude

http://maps.googleapis.com/maps/api/geocode/json?latlng=10.32,123.90&sensor=true

+5

Android API- !

getFromLocation (double, double, int) - , .

+7

:

private String getZipCodeFromLocation(Location location) {
    Address addr = getAddressFromLocation(location);
    return addr.getPostalCode() == null ? "" : addr.getPostalCode();
}

private Address getAddressFromLocation(Location location) {
    Geocoder geocoder = new Geocoder(this);
    Address address = new Address(Locale.getDefault());
    try {
        List<Address> addr = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
        if (addr.size() > 0) {
            address = addr.get(0);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return address;
}

, .

+2

All Articles