当我点击GPS-link
然后我尝试url
在a
标签中实现。但它不起作用!
jQuery:
$(document).ready(function(){
/* add geolocation */
$("a.target").click(function(){
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
}
else
{
alert("Geolocation is not supported by this browser.");
}
}
function showPosition(pos){
var lat = pos.coords.latitude;
var lon = pos.coords.longitude;
/* GPS link */
$("a.target").attr("href",
"http://dev.market-locator.com/geolocation-lijst?distance[latitude]="
+ lat + "&distance[longitude]=" + lon
+ "&distance[search_distance]=20&distance[search_units]=km");
}
});
HTML:
...
<a class="target">Link</a>
...