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

  • Home
  • SEARCH
  • 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 6041965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:44:16+00:00 2026-05-23T06:44:16+00:00

Having problems getting the different arrays content from geocoder results. item.formatted_address works but not

  • 0

Having problems getting the different arrays content from geocoder results.

item.formatted_address works but not item.address_components.locality?

geocoder.geocode( {'address': request.term }, function(results, status) {

        response($.map(results, function(item) {

        alert(item.formatted_address+" "+item.address_components.locality)
    }            
}); 

// the array returned is;

 "results" : [
      {
         "address_components" : [
            {
               "long_name" : "London",
               "short_name" : "London",
               "types" : [ "locality", "political" ]
            } ],
          "formatted_address" : "Westminster, London, UK" // rest of array...

any help appreciated!

Dc

  • 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-05-23T06:44:17+00:00Added an answer on May 23, 2026 at 6:44 am

    Got this working in the end using:

    var arrAddress = item.address_components;
    var itemRoute='';
    var itemLocality='';
    var itemCountry='';
    var itemPc='';
    var itemSnumber='';
    
    // iterate through address_component array
    $.each(arrAddress, function (i, address_component) {
        console.log('address_component:'+i);
    
        if (address_component.types[0] == "route"){
            console.log(i+": route:"+address_component.long_name);
            itemRoute = address_component.long_name;
        }
    
        if (address_component.types[0] == "locality"){
            console.log("town:"+address_component.long_name);
            itemLocality = address_component.long_name;
        }
    
        if (address_component.types[0] == "country"){ 
            console.log("country:"+address_component.long_name); 
            itemCountry = address_component.long_name;
        }
    
        if (address_component.types[0] == "postal_code_prefix"){ 
            console.log("pc:"+address_component.long_name);  
            itemPc = address_component.long_name;
        }
    
        if (address_component.types[0] == "street_number"){ 
            console.log("street_number:"+address_component.long_name);  
            itemSnumber = address_component.long_name;
        }
        //return false; // break the loop   
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having problems figuring this out. trying to do a rescue_from NoMethodError, :with => :try_some_options
I am trying to display a form inside a shadowbox but am having some
I'm having a problem getting the BlendState on the graphics device to work properly
I'm using the zend framework to write an app and I'm having lots of
i am having a problem with the way that i am trying to delete
I am trying to send a request to an url like this http://mysite.dk/tværs?test=æ from
I have a main website app written in ASP.NET's MVC 3. Now, what I
One of my unit tests seems to randomly pass or fail when I run
I have 2 sprites which when drawn together make up the correct image on
I'm using the default settings in Eclipse to export my application and have Proguard

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.