1

この URL に緯度経度 の変数 を追加するにはどうすればよいですか。

<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);
};
4

1 に答える 1

0

Construct the URL with concatenated strings like:

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

Then set the href= to URL with jQuery

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

or by modifying the attribute in javascript.

于 2013-10-29T19:56:16.273 に答える