How do I change the scale displayed in Google Maps API v3 to imperial (miles) units

后端 未结 5 1109
离开以前
离开以前 2020-12-31 05:45

I\'m simply displaying a map, with no routing or directions. I can add the control with mapOptions = {...scaleControl: true,...} but I could find no documentation about cha

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-31 06:37

    Ok so I came up with this BUT I would use this as a short term fix only.

    function switchScale(mapId){
        var spn = document.getElementById(mapId).getElementsByTagName("span");
        for(var i in spn){ 
            if( (/\d+\s?(mi|km)/g).test(spn[i].innerText) ){ 
                spn[i].click(); 
            } 
        }
    }
    

    This worked in chrome but I've heard that '.click()' can cause issues in some browser that use '.onclick()' instead.

提交回复
热议问题