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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:30:19+00:00 2026-06-11T09:30:19+00:00

function getLatLng(address) { geocoder.geocode({ ‘address’ : address }, function(results, status) { if (status ==

  • 0
function getLatLng(address) {
    geocoder.geocode({
        'address' : address
    }, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            alert("Aus getLatLng: adresse:"+address+"Ergebnis: "+results[0].geometry.location);
            return results[0].geometry.location;
        } else {
            alert("Geocode was not successful for the following reason: "
                    + status);
        }
    });
}

I am using this javascript function in another function to get the Latitude/Longitude values from a string which is the address. The alert shows that the conversion is successfull but if i call the method i get a javascript error that it’s still undefined.

    var start = document.getElementById("route_start").value;
    start = getLatLng(start);
    alert("Start: "+start);

What am i missing? The alert always shows an undefined variable. Why is that?
I tried everything. Everything is going well til i call the function getLatLng. Something with the return isn’t working. 🙁

  • 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-11T09:30:21+00:00Added an answer on June 11, 2026 at 9:30 am

    Your getLatLng function doesn’t actually return anything, which is why start is undefined.

    The return statement that you have written is contained within the anonymous function that gets passed to geocoder.geocode, so this won’t actually get returned from your outer function.

    Since geocoder.geocode is asynchronous you won’t be able to write a getLatLng which returns the result in this way, instead you need to pass a callback function as an argument and invoke this function when the geocode API returns a value, something like:

    function getLatLng(address, callback) {
        geocoder.geocode({
            'address' : address
        }, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                callback(results[0].geometry.location);
            } else {
                alert("Geocode was not successful for the following reason: "
                        + status);
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following code to geocode a supplied address using the Google Maps
I am using Google Maps API for reverse lookup of an address, specifically Country,
I'm using the Google Maps Javascript API V3 to reverse-geocode a lot of locations
I'm making a page that utilizes the Google Maps geocoder object to find a
I am using google maps geocoder which uses an asynchronous to return the lat
function Apple(){ this.name=apple; } function Orange(){ this.name=orange; this.apple = new Apple(); this.apple.onCalled=function(){ alert(this.name); }
function getUser() { FB.api('/me', function(response) { console.log('Response is '+response); alert('Your name is ' +
function getDbValue() { alert($('[data-bind]').length); alert($('[data-bind][0].data-bind')); alert($('[data-bind][0].value')); jQuery.each($('[data-bind]'), function(databind,key) { alert(key); alert(databind); alert(databind[key].data-bind); }) }
I'm using Google Maps' local search, to find businesses in the area of an
On my web page I have already a Google Maps API with a search

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.