Advertisement
pestovpvl2

Untitled

Jan 24th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.24 KB | None | 0 0
  1. $("#formZip").submit(function (event) {
  2.             $("#result").text("");
  3.             var zip = $(this).find("input[name='s']").val();
  4.             var zipPersonArr = [];
  5.             $(".zip-val-option").each(function (index) {
  6.                 zipPersonArr.push($(this).text());
  7.             });
  8.  
  9.             var objectKeyVal = new Object();
  10.             /* Loop each value from array */
  11.             var count = $(".filters-group > div").length;
  12.             var iCount = 1;
  13.             var textInfo = "";
  14.             console.log("aft" + iCount);
  15.             zipPersonArr.forEach(function (element) {
  16. /* Ниже запрос */
  17.                 $.post(
  18.                     "https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=" + zip + "&destinations=" +
  19.                     element + "&key=AIzaSyAucEe5UVmL_dqOiCv4XaAxG94Ffr5L6sI", {
  20.                         func: "getNameAndTime"
  21.                     },
  22.                     function (data) {
  23.  
  24.                         console.log(Object.values(data)[2]["0"].elements["0"].distance.value);
  25.                         var distaseVal = Object.values(data)[2]["0"].elements["0"].distance.value;
  26.                         console.log("Distanse:" + distaseVal + ", Zip:" + element);
  27.                         $("#result").append(distaseVal + ":" + element + "|");
  28.                     }, "json");
  29.  
  30.                 if (iCount == count) {
  31.                     getFromResultDiv();
  32.                 }
  33.                 iCount++;
  34.             }); /* End Loop each zip */
  35.             console.log("Text info" + textInfo);
  36.             return false;
  37.  
  38.         });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement