Extracting plus 4 zip code from geocoding using google API, jQuery -


i using geo coding using google api of jquery. following code tried.

jquery(document).ready(function () { var geocoder = new google.maps.geocoder(); jquery('addresspicker1').autocomplete({     source: function (request, response) {         geocoder.geocode({ address: request.term}, function (results, status) {         if (status === google.maps.geocoderstatus.ok) {           response(jquery.map(results, function(item) {           var streetnumber = "";           var streetname = "";           var cityname = "";           var zip = "";           var country = "";           var countyname = "";           var state = "";              ( var component =0; component < item.address_components.length; component++ ) {              if (item.address_components[component] != undefined && item.address_components[component] != null ) {                   if ( jquery.inarray("street_number", item.address_components[component].types) > -1 ){                       streetnumber = item.address_components[component].long_name;                   }                    if ( jquery.inarray("route", item.address_components[component].types) > -1){                       streetname = item.address_components[component].long_name;                   }                    if ( jquery.inarray("locality", item.address_components[component].types) > -1){                       cityname = item.address_components[component].long_name;                   }                    if ( jquery.inarray("postal_code", item.address_components[component].types) > -1){                       zip = item.address_components[component].long_name;                   }                    if ( jquery.inarray("country", item.address_components[component].types) > -1){                       country = item.address_components[component].long_name;                   }                    if ( jquery.inarray("administrative_area_level_2", item.address_components[component].types) > -1){                         countyname = item.address_components[component].long_name;                   }                    if ( jquery.inarray("administrative_area_level_1", item.address_components[component].types) > -1){                         state = item.address_components[component].short_name;                    }             }           }     return {         label : item.formatted_address,         value : item.formatted_address,         latitude : item.geometry.location.lat(),         longitude : item.geometry.location.lng(),         streetno : streetnumber,         streetname : streetname,         city : cityname.touppercase() ,         zip : zip,         country : country,         county : countyname.touppercase(),         state : state     }       }));    }  });  },  select: function (event, ui) {       jquery('streetnumber').val(ui.item.streetno);       jquery('streetname').val(ui.item.streetname);       jquery('city').val(ui.item.city);       jquery('zip').val(ui.item.zip);       jquery('country').val(ui.item.country);       jquery('countyname').val(ui.item.county);       jquery('statecode').val(ui.item.state);       jquery('geocodedlatitude').val(ui.item.latitude);       jquery('geocodedlongitude').val(ui.item.longitude);   } 

i faced problem during searching plus 4 zip codes. didn't additional 4 digits in response. example ,for search text, "60 main st,huntington ny 11743-6961". retrieved '11743' through 'postal_code' attribute in response. cant able retrieve '6961' response.

is there options full zip code in scenario?

or need try other way search plus 4 zip code.

thanks in advance.

as far know, google's geocoder doesn't append zip +4 (addon) codes.

google doesn't verify addresses, includes standardizing format, in turn includes appending zip+4 code.

what need api standardizes , validates addresses. api liveaddress want. return address components, including +4 addon code.

i'm developer @ smartystreets. here's example of response address give in question, +4 code use -- there 2 +4 codes @ delivery point because 1 firm, ymca, , i'll show 1 here:

{     "input_index": 0,     "candidate_index": 1,     "addressee": "ymca",     "delivery_line_1": "60 main st",     "last_line": "huntington ny 11743-6961",     "delivery_point_barcode": "117436961606",     "components": {         "primary_number": "60",         "street_name": "main",         "street_suffix": "st",         "city_name": "huntington",         "state_abbreviation": "ny",         "zipcode": "11743",         "plus4_code": "6961",         "delivery_point": "60",         "delivery_point_check_digit": "6"     },     "metadata": {         "record_type": "f",         "county_fips": "36103",         "county_name": "suffolk",         "carrier_route": "c037",         "congressional_district": "03",         "rdi": "commercial",         "latitude": 40.87179,         "longitude": -73.42655,         "precision": "zip7"     },     "analysis": {         "dpv_match_code": "y",         "dpv_footnotes": "aabb",         "dpv_cmra": "n",         "dpv_vacant": "n",         "active": "y"     } } 

here's lookup on smartystreets homepage full results: http://smartystreets.com/?street=60%20main%20st&city=huntington&state=ny&zipcode=11743

anyway, difference been address validation , geocoding. geocoding merely turns address coordinates, if need +4 code, need address validation api. liveaddress 1 of few can use, should give better idea , can start search there.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -