Undefined need help

Hi, can ask some help I am having problem in processing the reverse geocode,…I want to convert the lat & lng into address but it seems like some address are undefined . can you help me please why is it undefined.

<!DOCTYPE html>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta http-equiv="content-language" content="en"/>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>

<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.exp&sensor=false&libraries=places"></script>

<script type="text/javascript">

var map;
var mycoordinates;
var mycoordinatesPath;
var initial;
var coordinateLatLng = [];
var datacoord = null;
var latlng;

var nextAddress = 0;
var r;
var address = [];
var delay = 100;
var progress;
var x = 0;
var mptype;

var latLngBounds = new google.maps.LatLngBounds();

function initialize() {
    geocoder = new google.maps.Geocoder();

    initial = new google.maps.LatLng(10.296954, 123.896785);

    var mapOptions = {
        zoom: 16,
        center: initial,
        mapTypeId: mptype

    map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);


function calcRoute() {

    datacoord = null;

    $('.mytablesearch').css('display', 'none');
    $('#loctable tr').nextAll().remove();

    var data = [


    datacoord = data;


function getAddress(nextAddress) {

    latlng = new google.maps.LatLng(datacoord[nextAddress].lat, datacoord[nextAddress].lng);

    geocoder.geocode({latLng:latlng}, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            if (results[1]) {
                var add = results[0].formatted_address;


            } else {
                console.log("no result found");

        } else {
            if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {

            } else {
                var reason = "Code " + status;
                var msg = 'address="' + latlng + '" error=' + reason + '(delay=' + delay + 'ms)<br>';
                console.log("MESSAGE=", msg);





function theNext() {

    if (nextAddress < datacoord.length) {

        setTimeout('getAddress("' + nextAddress + '")', delay);

    } else {
        $('.container-progressbar').css('display', 'none');
        console.log("Done loading");

function display(datacoord) {

    var lno = 1;
    $('.mytablesearch').css('display', 'block');
    for (var n = 0; n < datacoord.length; n++) {
        $('#loctable tr:last').after('<tr><td>' + lno + '</td><td>' + datacoord[n].lat + '</td><td>' + datacoord[n].lng + '</td><td>' + address[n] + '</td></tr>');


google.maps.event.addDomListener(window, 'load', initialize);

<style type="text/css">
        bottom: 17px;
        position: absolute;
        height: 170px !important;
        overflow: auto;
        width: 100%;




<div id="basic_map" data-role="page">
    <div data-role="content">

                   <div id="map_canvas" style="position:absolute; width:100%; height:100%;"></div>

                    <div class="mytablesearch">
                        <div class="table-responsive">
                            <table class="table table-striped" id="loctable">




Thank you in advance.

Hi jemz,

First of all, I know I’ve mentioned this to you before, but it’d be really helpful if you could try to use more descriptive thread titles. If you’d put something like “Need help with reverse geocoding using Google Maps”, for example, then you’re more likely to generate interest from forum members who might know something about the topic.

Regarding your question, the problem here is that you’re hitting the quota limit by submitting requests too frequently. I know you’ve got some checks in place to handle that, but unfortunately there are a couple things preventing them from working properly:

Your getAddress function defines an argument called nextAddress, which overrides the global nextAddress within the function’s scope. When you decrement nextAddress, you’re altering this local variable rather than the global one, and so the current set of coordinates is never processed again. What you need to do here is use a different name for the argument:

function getAddress(nextIndex) {
    latlng = new google.maps.LatLng(datacoord[nextIndex].lat, datacoord[nextIndex].lng);

The other problem is that you’re only incrementing the delay by one millisecond, which isn’t going to make any difference. Google’s map API docs suggest a delay of 2 seconds after receiving the OVER_QUERY_LIMIT status. In my tests, an initial delay of 0.75 seconds between requests will allow you to process 9 sets of coordinates before hitting a rate limit, so you might want to play around with the delays to find an optimal setting.

Hi fretburner,

Thank you so much for the reply…I will try your solution and i will let you know :slight_smile:

Hello fretburner,

I just tested it and i think it’s working i can see now the address :)…Thank you so much