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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:29:23+00:00 2026-05-26T13:29:23+00:00

I am using Google maps v3 geocoder to geocode an address then pass the

  • 0

I am using Google maps v3 geocoder to geocode an address then pass the 2 coordinate points from the jQuery file to a PHP file using getJSON.

Problem: However, I notice that the function that does the geocoding function keeps returning an undefined value! Thus the PHP file receives a undefined variable. Where did I go wrong?

jQuery Code

var search_latlng = geocodeAddress(search_location);
console.log(search_latlng);

$.getJSON('/main/get_places', {search_location: search_latlng}, function(json){
        $("#result_listing").html('');
 .
 .
 .

Geocoder JS function

function geocodeAddress(address) {

    var latlng = new Array(2);

    geocoder.geocode( { 'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            latlng[0] = results[0].geometry.location.lat();
            latlng[1] = results[0].geometry.location.lng();
            return latlng;
        } else {
            console.log("Geocode was not successful for the following reason: " + status);
        }
    });
}
  • 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-26T13:29:24+00:00Added an answer on May 26, 2026 at 1:29 pm

    You can’t return a value from that function via the callback to the Google code. It makes no sense; the “geocode()” function is asynchronous. The outer function will have returned by the time that your callback runs.

    The proper way to do this is to mimic the Google API itself: give your function a callback parameter, and perform your “afterwards” work from there:

    function geocodeAddress(address, callback) {
    
        var latlng = new Array(2);
    
        geocoder.geocode( { 'address': address}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                latlng[0] = results[0].geometry.location.lat();
                latlng[1] = results[0].geometry.location.lng();
                callback(latlng); // call the callback function here
            } else {
                console.log("Geocode was not successful for the following reason: " + status);
            }
        });
    }
    

    edit — as an example of how you’d use this:

    geocodeAddress(search_location, function(search_latlng) {
      console.log(search_latlng);
      $.getJSON('/main/get_places', {search_location: search_latlng}, function(json){
        $("#result_listing").html('');
        // ...
      });
    });
    

    It’s like your original code, but instead of having the geocode result returned to your code, it’s passed as the parameter to the callback function you provide.

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

Sidebar

Related Questions

I am using the following method to reverse geocode a google maps latlng: [GClientGeocoder.getLocations(address:String,
I'm using google maps API. I use a $.getJSON on .keyup() to geocode the
I'm using the following code to geocode a supplied address using the Google Maps
I am using google maps geocoder to geocode a zipcode and I want it
It seems that licensing terms would prevent us from using Google Maps API in
I'm using Google's Geocoder to find lat lng coordinates for a given address. var
I am using geolocation to get the address of places on my google maps
I'm using http://maps.google.com/maps/geo ? web service to geocode some addresses. The problem I have
Hi I am having issues inserting a map from google maps and using the
How do you do a Reverse Geocode on the clientside using Google Maps V3

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.