Click here to Skip to main content
15,798,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This is may javascript data for google map distance for working but that show only foirst 10 labels after the labels distance not showing please help this problem
Description
button click fetch the data into labels and that data is compare every time to google map map also coming in a label distance is not coming

C#
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var n;
function InitializeMap()
{

    directionsDisplay = new google.maps.DirectionsRenderer();
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions =
    {
        zoom: 11,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map"), myOptions);


    directionsDisplay.setMap(map);
            directionsDisplay.setPanel(document.getElementById('directionpanel'));

    var control = document.getElementById('control');
    control.style.display = 'block';

document.getElementById('sorttable').style.display="none"

}
    function calcRoute(dist,val)
    {
alert(val);
    var start = document.getElementById('startvalue').value;
    var end = document.getElementById(dist).innerHTML;
     end=end.replace(/[!@#$%&^*()-+=|\/:;><~]/gi," ");

    var request = {
        origin: start,
        destination: end,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
    directionsService.route(request, function (response, status)
    {
        if (status == google.maps.DirectionsStatus.OK)
         {

         document.getElementById('sorttable').style.display="block";
         document.getElementById("total").style.visibility="hidden";
            directionsDisplay.setDirections(response);
            var route = response.routes[0];
            //alert(val);
             for (var i = 0; i < route.legs.length; i++)
             {
              //alert(route.legs.length);
             //var array_list=[];
                 var a=route.legs[i].distance.text;
                 var b=route.legs[i].duration.text;

                 var bc=a+",About :"+b;

                 var lblid="Labe"+val;
                  //alert(lblid);
                document.getElementById(lblid).innerHTML=bc;

              
        }



        }
      }
    );

    }


function Button1_onclick()
{

document.getElementById('sorttable').style.display="block";
n=document.getElementById('Countnumbers').value;
for(var j=1; j<=n;j++)
{

        var ss="lblstorename"+j;
        var ss1 =document.getElementById(ss).innerHTML;
        var store="lblstore"+j;
        document.getElementById(store).title=ss1;
        calcRoute(ss,j);

  }

}
Posted
Comments
Zoltán Zörgő 30-Jun-12 8:03am    
You should know that google api has a fair-use policy, thus you can do only a limited amount of calls per minute, or you are excluded for an other amount of time (I don't know the amounts exactly). Thus you should include some random wait times between api calls.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900