2
votes

i'm currently using Google Geocoder API to determine location data for my web service. It's important for me to get the postal code for a given country and city, but it's look like that google is limiting the result.

Here's the API call:

http://maps.googleapis.com/maps/api/geocode/json?address=deutschland,+saarlouis&language=de&sensor=false

The result is like that:

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "Saarlouis",
               "short_name" : "Saarlouis",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Landkreis Saarlouis",
               "short_name" : "Landkreis Saarlouis",
               "types" : [ "administrative_area_level_3", "political" ]
            },
            {
               "long_name" : "Saarland",
               "short_name" : "SL",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Deutschland",
               "short_name" : "DE",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Saarlouis, Deutschland",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 49.36187570,
                  "lng" : 6.815549499999999
               },
               "southwest" : {
                  "lat" : 49.26046930,
                  "lng" : 6.67501510
               }
            },
            "location" : {
               "lat" : 49.31346060,
               "lng" : 6.752286499999999
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 49.36187570,
                  "lng" : 6.815549499999999
               },
               "southwest" : {
                  "lat" : 49.26046930,
                  "lng" : 6.67501510
               }
            }
         },
         "types" : [ "locality", "political" ]
      }
   ],
   "status" : "OK"
}

Thx for help.

Regards

2

2 Answers

0
votes

Geocoding does not give postcode. Goenames has a database for Germany. Other countries are also available.

0
votes

The reason you don't get the postal code is the query is too broad. If you would add a street name to the query the result will contain a postal code. A solution to your problem if you don't have a street name or don't want to use it is to split the geocoding into two parts:

Step 1: Use the city to get the GPS coordinates

https://maps.googleapis.com/maps/api/geocode/json?address=amsterdam

Step 2: Use the the GPS coordidates to get the postal code

https://maps.googleapis.com/maps/api/geocode/json?latlng=52.3182742,4.7288558

(Note: Double of same question posted here, answered by MidnightMotion. Adding to make easier to lookup. https://gis.stackexchange.com/questions/33966/google-geocoder-lookup-get-postal-code-by-country-and-city)