Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8835767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:20:05+00:00 2026-06-14T09:20:05+00:00

I’ve been trying to figure this out for so long that I’m sure it’s

  • 0

I’ve been trying to figure this out for so long that I’m sure it’s staring me in the face.

I’m using jquery to auto complete an address being entered by a user with the following code:

    $(function() {
      $("#address").autocomplete({
      //This bit uses the geocoder to fetch address values
      source : function(request, response) {
      geocoder.geocode({'address' : request.term },

function(results, status) {
   response($.map(results, function(item) {
   return {
      label : item.formatted_address,
      value : item.formatted_address,
      latitude : item.geometry.location.lat(),
      longitude : item.geometry.location.lng(),
      streetNo : item.address_components[0].long_name,
      streetName : item.address_components[1].long_name,
      town : item.address_components[2].long_name,
      province : item.address_components[4].long_name,
             }
         }));
      })
  }

I need to extract the address components specfically i.e. postal code. Right now I’m using numbers but depending on the address inputted, the fields may or may not be correct.

I pretty much have the same question this guy did:

Google Maps Geocoder: Return postal_code

The answer to that question is appropriate but the issue I”m having his when I try to loop, or do anything other than extract the info the way it’s already done here the script fails.

Based on the way the jquery autocomplete does it’s google query, can I assign the “results” to a variable and then parse it that way for correct type names?

Everything I’ve tried so far has failed, usually resulting in the script not running.

I’m getting desperate here, hopefully my question is coherent! 😛

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:20:06+00:00Added an answer on June 14, 2026 at 9:20 am

    Okay folks so I managed to figure out. Posting the answer here in case anyone else ever gets stuck on this thing.

    The way it has been coded allows the programmer to extract exactly what type they are looking for by using a function written in another answer on stackoverflow:

    More efficient way to extract address components

    I used user: Johann’s answer but I’ll include my code just to have a bigger overall “scope” for other ‘hobby’ programmers like me who may have a hard time “bridging the gap”.

    $(function() {
        $("#address").autocomplete({
            //This bit uses the geocoder to fetch address values
            source : function(request, response) {  
    
                geocoder.geocode({
                    'address' : request.term
                },function(results, status) {
                    //Here we take the response and manipulate the map
                    response($.map(results, function(item) {
                        //Function here to be called by the variables we want, essentially it loops through the array
                        //of address_components that come back from the geolocate, and loops until it finds the 'type'
                        //Entered in the "return" section below
                        function extractFromAdress(components, type){
                            for (var i=0; i<components.length; i++)
                                for (var j=0; j<components[i].types.length; j++)
                                    if (components[i].types[j]==type) return components[i].long_name;
                                return "";
                                }
                        //Returns the variables, left of the ':' to the script
                        //Code right of the ':' is whatever we want to assign to the variable
                        return {
                            label : item.formatted_address,
                            value : item.formatted_address,
                            //Lat and Long from the geo-locate
                            latitude : item.geometry.location.lat(),
                            longitude : item.geometry.location.lng(),
                            //Typical street address values a user would input, and what a typical program would need.                          
                            streetNo : extractFromAdress(item.address_components, "street_number"),
                            streetName : extractFromAdress(item.address_components, "route"),
                            town : extractFromAdress(item.address_components, "administrative_area_level_3"),
                            province : extractFromAdress(item.address_components, "administrative_area_level_1"),
                            postal : extractFromAdress(item.address_components, "postal_code"),
                        }
    
                    }));
                })
            }
    

    For a reference of which types are available from the addresses, check this link:

    https://developers.google.com/maps/documentation/geocoding/index#JSON

    Cheers everyone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a jquery bug and I've been looking for hours now, I can't
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm trying to create an if statement in PHP that prevents a single post
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.