gpt4 book ai didi

javascript - HTML5 地理位置 url 中的纬度/经度

转载 作者:行者123 更新时间:2023-11-28 08:46:48 25 4
gpt4 key购买 nike

如何在此网址中添加 latlon 变量:

<a class="geo" href="http://dev.site.com/geolocation?distance[latitude]=LAT&distance[longitude]=LON&distance[search_distance]=20&distance[search_units]=km">GPS</a>

来自:http://jsfiddle.net/yJrtR/14/的javascript

window.onload = function () {
var latElement = document.getElementById("lat"),
lonElement = document.getElementById("lon"),
lastUpdatedElement = document.getElementById("last_updated"),
watchPositionOptions = {
enableHighAccuracy: false,
timeout: 10000,
maximumAge: 0
};
navigator.geolocation.watchPosition(function (position) {
console.log("Successfully retrieved position: ", position);
var coords = position.coords;

latElement.innerHTML = coords.latitude;
lonElement.innerHTML = coords.longitude;

lastUpdatedElement.innerHTML = new Date(position.timestamp);
}, function (error) {
console.log("Something went wrong retrieving position: ", error);
}, watchPositionOptions);
};

最佳答案

使用连接的字符串构造 URL,例如:

var URL = "http://dev.site.com/geolocation?";
URL =+ "distance[latitude]=" + LAT;
URL =+ "&distance[longitude]=" + LON;
URL =+ "&distance[search_distance]=20&distance[search_units]=km";

然后使用 jQuery 将 href= 设置为 URL

 $("a.target").attr("href", URL);

或者通过修改javascript中的属性。

关于javascript - HTML5 地理位置 url 中的纬度/经度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19667485/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com