如何添加地址并使其可点击,这将被重定向到谷歌地图。 类似于下面的代码:
<a href="tel:+123456789">+123456789</a>
但对于地址。
一个人应该能够点击地址并在谷歌地图上获取位置。 如果我能动态地做就更好了。
尝试使用此方法获取可点击的地址以重定向谷歌地图:
<!DOCTYPE html>
<html>
<head>
<title>Clickable Address Link to Google Maps</title>
</head>
<body>
<p>Click on the address to view it on Google Maps:</p>
<a id="addressLink" href="#">Loading Address...</a>
<script>
// Replace this value with the actual address
const address = "United Kingdom";
const addressLink = document.getElementById("addressLink");
addressLink.textContent = address;
addressLink.href = `https://www.google.com/maps/search/${encodeURIComponent(address)}`;
</script>
</body>
</html>