Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Maps API sometimes not returning PostalCode within AddressDetails
    primarykey
    data
    text
    <p>I created a function to take location input, pass it to Google Maps Javascript API V2, and return a latitude/longitude/<strong>normalized address that I'll have to split into different fields in a database (i.e. city, state, postal)</strong>. I'm requiring at least a <a href="http://code.google.com/apis/maps/documentation/javascript/v2/reference.html#GGeoAddressAccuracy" rel="nofollow noreferrer">level 5/post code accuracy</a> for the input so that the returned data from Google will always have...</p> <ul> <li>Country</li> <li>City (Locality)</li> <li>State (Administrative Area)</li> <li>Postal</li> <li>Lat/Long</li> </ul> <p>Here's some info on the JSON object structure that Google returns. <a href="http://code.google.com/apis/maps/documentation/javascript/v2/services.html#Geocoding_Structured" rel="nofollow noreferrer">http://code.google.com/apis/maps/documentation/javascript/v2/services.html#Geocoding_Structured</a></p> <p><strong>Problem</strong>: For some instances, Placemark.AddressDetails will not include a postal code, while the summarized Placemark.address will include the postal code.</p> <p>For example, the following input examples will return a postal code inside Placemark.address, but not Placemark.AddressDetails; </p> <ul> <li>10437 Innovation Drive, Milwaukee, WI 53226</li> <li>MOMA</li> <li>Empire State Building --> this actually returns the postal code inside of some weird "DependentLocality" under SubAdministrativeArea.Locality</li> </ul> <p>Here's my troubleshooting code:</p> <pre><code>&lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt; &lt;!-- You must insert your maps API script here. --&gt; &lt;script language="javascript" type="text/javascript" src="http://www.json.org/json2.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { var geocoder = new GClientGeocoder(); $.geolocateAddress = function(address) { geocoder.getLocations(address, function(response) { if (response != null &amp;&amp; response.Placemark != undefined) { var placemark = response.Placemark[0]; // Placemark has Post code or higher accuracy -&gt; http://code.google.com/apis/maps/documentation/javascript/v2/reference.html#GGeoAddressAccuracy if (placemark.AddressDetails.Accuracy &gt;= 5) { alert(placemark.address); try { alert(placemark.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode.PostalCodeNumber); } catch (err) { alert('What the deuce? Why is there no postal code?... I bet you the placemark.address has the postal code.'); alert(JSON.stringify(placemark)); } } else { alert('Sorry, this requires at least a postal code input for accuracy') } } else { alert('Failed to geo locate address'); } }); }; $("#location").blur(function(event) { var address = $("#location").val(); $.geolocateAddress(address); }); }); &lt;/script&gt; &lt;form action="" method="get"&gt; &lt;input title="Location" type="text" value="" id="location" /&gt; &lt;/form&gt; </code></pre> <p>Phew... Is there something I'm just not understanding about schema of Google Maps placemarks? Would I be able to solve this problem by upgrading to Google Maps Javascript API V3? (V2 JSON objects seems more intuitive IMO) <a href="http://code.google.com/apis/maps/documentation/javascript/services.html" rel="nofollow noreferrer">http://code.google.com/apis/maps/documentation/javascript/services.html</a></p> <p>I'm about to throw in the towel on this. Hopefully somebody can help!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload