Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

How to load the google map scale in miles unit by default

I have used the below code to load the map scale in miles unit by default while the google map is loaded. But this code only works if the google map loads fully before the given timeout (60000 ms). So the code has dependency on the map loading time out. As a result of which this code is working sometimes on and off. Can someone help me to get rid of this so that it works for all circumstances?

window.setTimeout(function() {
  var spn = document.getElementById("map").getElementsByClassName("gm-style-cc");
  for (var i in spn) {
   //look for km or m in innerText via regex https://regexr.com/3hiqa
    if ((/\d\s?(km|(m\b))/g).test(spn[i].innerText)) {
      spn[i].click();
    }
  }
}, 60000);

Comments