title: Google Maps Address Components Geocoding vs Places API - Short vs Long Name
body: <p>Hey there GMaps API developers. To start - what an incredible product and service the Google Maps/JS API v3 is - thank you so much! Now, with that important bit of sincere gratitude out of the way...</p>
  
  <p>The <code>short_name</code> vs <code>long_name</code> options for address components is a nice feature, but for each service these two attributes mostly contain the same values, except geocode has what I would expect for <code>short_name</code> for both and places has what I would expect for <code>long_name</code> for both! *tears*</p>
  
  <p>Before Places library came out I just assumed that Google didn't actually have short/long versions for street name, localities, etc - but now it seems you <strong>do</strong> have that formatting somewhere - maybe different product teams have different databases?</p>
  
  <p>So what's the deal?</p>
  
  <p>Image of what I'm talking about (would embed but this is my first stackoverflow question so no reputation): <a href="http://i.imgur.com/XPVj8.png" rel="nofollow">http://i.imgur.com/XPVj8.png</a></p>
  
  <p>Detailed list of how I <strong>wish</strong> this worked:</p>
  
  <ul>
  <li>for routes, geocode's <code>short_name</code> places' <code>long_name</code></li>
  <li>have the same "types" value for locality/sublocality between geocode and places (either is fine, just pick one)</li>
  <li>consistently provide short/long for state (administrative_area_level_1) - geocode gets this right but places doesn't</li>
  <li>same for country - and where is geocode getting its "USA" in the formatted address?</li>
  <li>would be neat if <code>postal_code</code> <code>long_name</code> had zip+4, but I would imagine that'd be a huge endeavor from a data standpoint</li>
  </ul>
  
  <p>Thanks so much - looking forward to any insight on this behavior!</p>
  
  <p>Code behind the image:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;title&gt;GMaps API V3 Geocoder vs Places Address Components | Short vs Long Name&lt;/title&gt;
    &lt;script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true&amp;libraries=places"&gt;&lt;/script&gt;
    &lt;style type="text/css"&gt;
      #map {height: 100px; width: 600px; border: 1px solid #333; margin-top: 0.6em; }
      table { border-collapse: collapse; border-spacing: 0; }
      table td {border-top: 1px solid #DDD; padding:4px 8px; }
    &lt;/style&gt;
    &lt;script type="text/javascript"&gt;
      var map, geocoder, places, geocode_components, geocode_formatted, places_components, places_formatted
      function initialize() {
        geocoder = new google.maps.Geocoder();
        geocoder.geocode({'address': '3 South Main Street, York New Salem, PA'},
        function (results, status) {
          geocode_components = results[0].address_components;
          geocode_formatted = results[0].formatted_address;
          map = new google.maps.Map(document.getElementById('map'), {
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            center: results[0].geometry.location,
            zoom: 10
          });
  
          places = new google.maps.places.PlacesService(map);
          places.search({location: results[0].geometry.location, radius:100, keyword: "Pizza"},
            function(results, status) {
              //get details - this feels a little extraneous to me, but y'all know best
              places.getDetails({reference: results[0].reference},
              function(result, status) {
                places_components = result.address_components;
                places_formatted = result.formatted_address;
                writeResults();
              });
            });
        });
      }
  
      function writeResults() {
      tbody = document.getElementById('results');
      formatted = document.getElementById('formatted');
      var rows = "";
      for(var i=0; i&lt;geocode_components.length; i++) {
        var c = geocode_components[i];
        rows = rows + '&lt;tr&gt;&lt;td&gt;Geocoding&lt;/td&gt;&lt;td&gt;' + c.types[0] + '&lt;/td&gt;&lt;td&gt;' + c.short_name + '&lt;/td&gt;&lt;td&gt;' + c.long_name + '&lt;/td&gt;&lt;/tr&gt;';
      }
  
      for(var i=0; i&lt;places_components.length; i++) {
        var c = places_components[i];
        rows = rows + '&lt;tr&gt;&lt;td&gt;Places&lt;/td&gt;&lt;td&gt;' + c.types[0] + '&lt;/td&gt;&lt;td&gt;' + c.short_name + '&lt;/td&gt;&lt;td&gt;' + c.long_name + '&lt;/td&gt;&lt;/tr&gt;';
      }
      tbody.innerHTML = rows;
      formatted.innerHTML = '&lt;br /&gt;Geocode Formatted: ' + geocode_formatted + '&lt;br /&gt;' + 'Places Formatted: ' + places_formatted;
    }
    google.maps.event.addDomListener(window, 'load', initialize);
    &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
    &lt;div id="map"&gt;&lt;/div&gt;
    &lt;table&gt;
      &lt;thead&gt;&lt;tr&gt;&lt;th&gt;Service&lt;/th&gt;&lt;th&gt;Type&lt;/th&gt;&lt;th&gt;Short Name&lt;/th&gt;&lt;th&gt;Long Name&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;
      &lt;tbody id="results"&gt;&lt;/tbody&gt;
    &lt;/table&gt;
    &lt;div id="formatted"&gt;&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>