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 8212625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:49:17+00:00 2026-06-07T10:49:17+00:00

OK, I am taking from an example I found, but my brain is fried

  • 0

OK, I am taking from an example I found, but my brain is fried from the heat, and google api’s always do something to me, anyway

function codeLatLng(lat, lng)
{
    var latlng = new google.maps.LatLng(lat, lng);
    geocoder.geocode({'latLng': latlng}, function(results, status)
    {
        if (status == google.maps.GeocoderStatus.OK)
        {
            //console.log(results)
            if(results[1])
            {
                //formatted address
                //alert(results[0].formatted_address)
                //find country name
                $('#geolocation_latlng').html(latlng);
                for(var i=0; i<results[0].address_components.length; i++)
                {
                    for(var b=0;b<results[0].address_components[i].types.length;b++)
                    {

                        //there are different types that might hold a city admin_area_lvl_1 usually does in come cases looking for sublocality type will be more appropriate
                        if(results[0].address_components[i].types[b] == "administrative_area_level_1")
                        {
                            //this is the object you are looking for
                            city=results[0].address_components[i];
                            break;
                        }
                    }
                }
            //city data
            //alert(city.short_name + " " + city.long_name)
            }
            else
            {
                alert("Could not Determin Location");
            }
      }
      else
      {
          alert("Location dection failed: " + status);
      }
    });
}

Its safe to assume the lat and lon are already being passed and I am getting a result, I commented out one alert for formated_address, What I am trying to do is figure out how I can take the zipcode, state, city from that formatted address and show it on screen. But like I said Im fried right now, and Im crunching a clock so I need a bit of help to kick start me.

  • 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-07T10:49:19+00:00Added an answer on June 7, 2026 at 10:49 am

    My demo is comical collection of braces, but the idea is to look inside the results.types for:

     "locality"                     // CITY
     "administrative_area_level_1"  // STATE
     "postal_code"                  // ZIP
    

    And as iterating, when you match these types, fill in the values. I asked for the country because this approach is explained in the docs to correspond to the US, but I have no idea, say if it’s valid in Singapore. As they say, it’s not an exact science.

    So if you expand, you might have to check for country first, and match to another wantedTypes object with different correspondences to Google Maps’ types (in another country the state might be Admin. area level 2).

    I use the short name because most likely you want AZ and not Arizona. I didn’t go as far to check if cities differ, e.g. St. Paul (short) vs. Saint Paul.

        if (status == google.maps.GeocoderStatus.OK) {
            if (results[0]) {
                var typeCorrespondence = {
                    "city": "locality",
                    "state": "administrative_area_level_1",
                    "zipcode": "postal_code"
                };
    
                var geocoderResults = {};
    
                var components = results[0].address_components;
    
                for (var i = 0; i < components.length; i++) {
                    for (var j = 0; j < components[i].types.length; j++) {
    
                        for (myType in typeCorrespondence) {
                            if (typeCorrespondence[myType] == components[i].types[j]) {
                                geocoderResults[myType] = components[i].short_name;
                            }
                        }
                    }
                }
                $("#result").val(JSON.stringify(geocoderResults));
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a validator for my models: But taking the example from
I have a block of text that im taking from a Gedcom ( Here
I am taking pictures from my custom UIImagePicker camera and saving the images inside
I am taking pictures from the iPhone camera using the UIImagePickerController Class. I am
I've got the following code that's taking photos from a flickr feed via JSON
When taking a database from a relatively un-normalized form and normalizing it, what, if
I am taking a picture from android phone camera and placing it on imageview.
I am taking a date from a JSON object in the format of 2012-12-31
I am taking the amount from one input box and creating a for...each loop
Has anyone tried taking a video from the camera and then using the video

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.