Skip to Content

issue in geocoder.geocode() to get a latitude and longitude.

Hello Experts,

I have a requirement to display location as a marker on the google map and the address are coming from the backed.

Now i have used for loop to take address one by one and pass to the method geocoder.geocode().

Now i can see that when the control come to this method, instead of going to the inner side of method it is going back to loop.

following is the code:--

for (var i = 0; i <= oData.results.length; i++)

{ var address = oData.results[i].ZADDRESS;

that.geocoder = new google.maps.Geocoder();

that.geocoder.geocode({ 'address': address },

function(results, status)

{ if (status == google.maps.GeocoderStatus.OK)

{ results[0];



Can you please tell me why control is not going into geocoder.geocode() ?

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Posted on May 16, 2018 at 09:52 AM

    Hi Deborshi De Sarkar,

    If the data comes from back-end is oData, then you can simply use data binding. For example see GeoMap with Spots, and forget the loop.

    Else please provide a GIT repository or attach a .zip file to see what's going on in the code.

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Miklos Sebestyen ,

      Thanks for this information.But i need to show direction from source to destination and data which is coming from the back end as a address like "Eiffel Tower, 5 Avenue Anatole France". So i think i have to convert address to latitude and longitude.After getting this i can display marker in google map.Please correct me if i am wrong.
  • Posted on May 17, 2018 at 08:51 AM

    Ok, I see now, so you only have the address of a location and using Google API to retrieve the geocode.

    The possible reason for not seeing the control going into "geocode()" callback function is the asynchronous behaviour of the calls. If the call never runs into the callback function then check the console log of the browser, that might be some network error.

    You should also output if the status is not OK. as the Google API documentation states, that might include some useful information.

    function codeAddress() {
      var address = document.getElementById("address").value;
      geocoder.geocode({ address: address }, function(results, status) {
        if (status == "OK") {
          var marker = new google.maps.Marker({
            map: map,
            position: results[0].geometry.location
        } else {
          alert("Geocode was not successful for the following reason: " + status);
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.