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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:53:56+00:00 2026-05-23T11:53:56+00:00

var geocoder = new google.maps.Geocoder(); geocoder.geocode({‘latLng’: foundLoc}, function(results, status) { if (status == google.maps.GeocoderStatus.OK)

  • 0
var geocoder = new google.maps.Geocoder();
            geocoder.geocode({'latLng': foundLoc}, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    if (results[1]) {
                        var loc = getCityState(results);
                    }
                }
            }); 

function getCityState(results)
        {
            var citystateArray = results[1].formatted_address.split(",",2);
            var city = citystateArray[0];
            var state = citystateArray[1].substring(1, 3);
            return (city + ', ' + state)
        }

This is what I use now, and this works about 90% of the time. Other times, the formatted_address contains a town and a city along with the state, other times just the town and city, other times everything you can dream of.

I haven’t yet found a CONSISTENT way of ALWAYS getting the city/state from a Google Maps API result. Do any of you guys have one? Thanks.

Example of one response that Google uses as an example on their page:

{
  "status": "OK",
  "results": [ {
    "types": [ "street_address" ],
    "formatted_address": "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA",
    "address_components": [ {
      "long_name": "1600",
      "short_name": "1600",
      "types": [ "street_number" ]
    }, {
      "long_name": "Amphitheatre Pkwy",
      "short_name": "Amphitheatre Pkwy",
      "types": [ "route" ]
    }, {
      "long_name": "Mountain View",
      "short_name": "Mountain View",
      "types": [ "locality", "political" ]
    }, {
      "long_name": "California",
      "short_name": "CA",
      "types": [ "administrative_area_level_1", "political" ]
    }, {
      "long_name": "United States",
      "short_name": "US",
      "types": [ "country", "political" ]
    }, {
      "long_name": "94043",
      "short_name": "94043",
      "types": [ "postal_code" ]
    } ],
    "geometry": {
      "location": {
        "lat": 37.4219720,
        "lng": -122.0841430
      },
      "location_type": "ROOFTOP",
      "viewport": {
        "southwest": {
          "lat": 37.4188244,
          "lng": -122.0872906
        },
        "northeast": {
          "lat": 37.4251196,
          "lng": -122.0809954
        }
      }
    }
  } ]
}

Sometimes those fields don’t have values, sometimes they do.

  • 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-23T11:53:56+00:00Added an answer on May 23, 2026 at 11:53 am

    Why do you parse formatted_address ?

    There are the address_components, you can walk through them and look for the ones with

    "types": [ "administrative_area_level_1", "political" ]// the state
    "types" : [ "locality", "political" ]//the city
    

    Here’s an example: http://jsfiddle.net/doktormolle/QWPCL/

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

Sidebar

Related Questions

$(function(){ //Location was set. Perform actions. $(#geocodesubmit).click(function(){ var geocoder = new google.maps.Geocoder(); geocoder.geocode( {
So I make a reverse geocoded call like so: var geocoder = new google.maps.Geocoder();
function getNewMessages(id) { clearJqGrid(); var lat; var lng; var jsonData; var geocoder = new
var y = new w(); var x = y.z; y.z= function() { doOneThing(); x();
I'm using Google's Geocoder to find lat lng coordinates for a given address. var
Here is the Listener I'm adding - var map; var geocoder; function initialize() {
I am using Google Maps V3 API and using its Geocoder to do reverse
How do you do a Reverse Geocode on the clientside using Google Maps V3
I am new with google maps api. I took some sample from the manual
I am trying to reverse geocode the latitude and longitude of my google maps

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.