Click here to Skip to main content
15,741,581 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello every one

<pre>     $.each(locations, function (i, item) {           															
					 if((app.distance(pastlatlong, item[0]+","+ item[1]))>0)						 
		    var directionsDisplay;
            var directionsService = new google.maps.DirectionsService();			
			directionsDisplay = new google.maps.DirectionsRenderer();
            var start = pastlatlong;
            var end = item[0]+","+ item[1];
            var request = {
                origin: start,
                destination: end,
                travelMode: google.maps.TravelMode.DRIVING
            directionsService.route(request, function (response, status) {				
                if (status == google.maps.DirectionsStatus.OK) {
                    if (response.routes && response.routes.length > 0) {
                        var routes = response.routes;
                        for (var j = 0; j < routes.length; j++) {
                            var points = routes[j].overview_path;                            
                            for (var i = 0; i < points.length; i++) {           													            
									document.getElementById("alllatlng").value+`['`+points[i].lat()+`','`+ points[i].lng()+`',`+`'FIRST'],`;
						    document.getElementById("alllatlng").value+`['`+item[0]+`','`+ item[1]+`','`+item[2]+`'],`;
					pastlatlong=item[0]+","+ item[1];				
				isPaused = false;

And this is the format of json object for location

when trying to run this the else statement string is binding first and then if condition string pls can any one find the cause.

Iam having a function with timeout after this method execution.

Please help me

What I have tried:

I have latitudes and longitudes in my database which was captured by mobile while driving. when there was no signal the lat longs have not captured so now I am fetching them from google api in driving mode and concatenating to my json
Updated 31-May-17 19:35pm
TheKarateKid 3-Jun-17 12:30pm    
have you tried using loadash.js library. It has way better handling for Array,Loops and repeats ....

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