Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Find Location (Latitude,longitude) from Zipcode

What could be the best way to get location for a given zipcode. Would it work for countries outside US/Canada .Thanks

like image 906
Qamar Suleiman Avatar asked Jan 10 '11 11:01

Qamar Suleiman


People also ask

Can you get GPS coordinates from an address?

To get GPS coordinates using Google Maps is really easy. There are two ways you can go about it. Firstly, go to maps.google.com and type in the address or location you are interested in. Once it has loaded, you can just look in the address bar and you'll see the coordinates are contained within the URL itself.

Can Google Maps find latitude longitude?

To search for a place, enter the latitude and longitude GPS coordinates on Google Maps. You can also find the coordinates of the places you previously found. Besides longitude and latitude, you can use plus codes to share a place without an address.


2 Answers

Use the Google geolocating API (try it out on google.com/maps):

Input for a Swiss ZIP code for example: CH-9014

or a french one: FR-34000

or german: de-12101

or US: us-90210

or canada: ca-J5Z 1A1

or china: cn-100000

for example:

yields

{
  "status": "OK",
  "results": [ {
    "types": [ "postal_code" ],
    "formatted_address": "9014 St Gallen, Switzerland",
    "address_components": [ {
      "long_name": "9014",
      "short_name": "9014",
      "types": [ "postal_code" ]
    }, {
      "long_name": "St Gallen",
      "short_name": "St Gallen",
      "types": [ "locality", "political" ]
    }, {
      "long_name": "Sankt Gallen",
      "short_name": "SG",
      "types": [ "administrative_area_level_1", "political" ]
    }, {
      "long_name": "Switzerland",
      "short_name": "CH",
      "types": [ "country", "political" ]
    } ],
    "geometry": {
      "location": {
        "lat": 47.4082855,
        "lng": 9.3323890
      },
      "location_type": "APPROXIMATE",
      "viewport": {
        "southwest": {
          "lat": 47.3991076,
          "lng": 9.3180504
        },
        "northeast": {
          "lat": 47.4199564,
          "lng": 9.3543340
        }
      },
      "bounds": {
        "southwest": {
          "lat": 47.3991076,
          "lng": 9.3180504
        },
        "northeast": {
          "lat": 47.4199564,
          "lng": 9.3543340
        }
      }
    }
  } ]
}

So the swiss ZIP code 9014 corresponds appx. to this location:

"lat": 47.4082855,
"lng": 9.3323890

See my answer on the geolocating API here:
How to get GLatLng object from address string in advance in google maps?

like image 131
Stefan Steiger Avatar answered Sep 19 '22 14:09

Stefan Steiger


GeoNames offers a number of various zipcode geocoding services, including search for the location of a given zipcode. They support a number of various countries.

You would probably be most interested in the Placename Lookup for postalcode service

like image 32
Claus Broch Avatar answered Sep 17 '22 14:09

Claus Broch