如何 在此 url 中 添加lat和lon变量:
<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>
来自的javascript:http: //jsfiddle.net/yJrtR/14/
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);
};