纬度和经度 google 地图中的最大长度
Maxlength in lat and long google maps
我正在尝试使用输入按钮中的最大长度来显示 google 地图的纬度和经度,但是最大长度不起作用...我做错了什么?
var marker = new google.maps.Marker({
draggable: true,
position: {lat: -47.00, lng: 18.00},
map: map,
});
google.maps.event.addListener(marker, 'dragend', function (event) {
document.getElementById("lat").value = event.latLng.lat();
document.getElementById("long").value = event.latLng.lng();
});
HTML:
Latitu: <input id="lat" name="lat" maxlength="6" value=""> <br />
Longi: <input id="long" name="long" maxlength="6" value=""/>
declares a limit on the number of characters a user can input
当您通过 JS 设置值时,它不是用户输入的。
您需要通过 JS 限制字符数:
document.getElementById("lat").value = String(event.latLng.lat()).substr(0,6);
我正在尝试使用输入按钮中的最大长度来显示 google 地图的纬度和经度,但是最大长度不起作用...我做错了什么?
var marker = new google.maps.Marker({
draggable: true,
position: {lat: -47.00, lng: 18.00},
map: map,
});
google.maps.event.addListener(marker, 'dragend', function (event) {
document.getElementById("lat").value = event.latLng.lat();
document.getElementById("long").value = event.latLng.lng();
});
HTML:
Latitu: <input id="lat" name="lat" maxlength="6" value=""> <br />
Longi: <input id="long" name="long" maxlength="6" value=""/>
declares a limit on the number of characters a user can input
当您通过 JS 设置值时,它不是用户输入的。
您需要通过 JS 限制字符数:
document.getElementById("lat").value = String(event.latLng.lat()).substr(0,6);