Google Places API Having Trouble with NYC Addresses


#1

I’m using https://github.com/lukemadera/meteor-autoform-googleplace and I’m having some trouble with putting in NYC area addresses… it can’t seem to compute that brooklyn, jamaica, far rockaway etc. are in NYC and it keeps throwing an error “city is required”

I wanted to see if anyone else has run into this before I start to dig too far into it.

Update:

It seems this is a common problem: https://github.com/vskosp/vsGoogleAutocomplete/issues/5


#2
  parseGoogleAddressComponent: function(addressComponents, params) {
    var address ={};
    //go through all address components and pull out the matching types and map them to what we want (city, state)
    var map ={
      'street_number': 'street',
      'route': 'street',
      'locality': 'city',
      'administrative_area_level_1': 'state',
      'postal_code': 'zip',
      'country': 'country'
    };
    var ii, xx;
    for(ii =0; ii<addressComponents.length; ii++) {
      for(xx in map) {
        //if have a map type we want
        if(addressComponents[ii].types.indexOf(xx) >-1) {
          //have to join street number and route together
          if((xx ==='street_number' || xx ==='route') && address.street !==undefined) {
            //prepend
            if(xx ==='street_number') {
              address.street =addressComponents[ii].short_name + ' ' +address.street;
            }
            //append
            else if(xx ==='route') {
              address.street =address.street + ' ' + addressComponents[ii].short_name;
            }
          }
          else {
            if(xx ==='locality') {
              address[map[xx]] =addressComponents[ii].long_name;
            }
            else {
              address[map[xx]] =addressComponents[ii].short_name;
            }
          }
        }
      }
    }

    return address;
  },

Where does the below get put in?

 function getCity(place) {
    var COMPONENT_TEMPLATE = { locality: 'long_name' },
        city = getAddrComponent(place, COMPONENT_TEMPLATE);
      if (!city || city == '') {
        COMPONENT_TEMPLATE = { sublocality_level_1: 'long_name'},
        city = getAddrComponent(place, COMPONENT_TEMPLATE);
      }
    return city;
}