0

如何在 php 中获取当前位置的经纬度”代码答案。下面是在 PHP 中取值进行地理定位的代码,这将对您有所帮助。有三个部分 1. php 部分 2. html 3. Jquery 所以你可以使用它在 php 中获取值。如果需要任何进一步的细节,请在评论部分发表评论

<?php

if(isset($_GET['clat']) && isset($_GET['clng']))
{
echo $_GET['clat'];
echo $_GET['clng'];
}
?>
<div >
<h1>Watch Position</h1>
<section>
<input type="button" id="startWatchButton" value="Watch Location" />
<input type="button" id="clearWatchButton" value="Stop" />

<label for="clat">Latitude:</label>
<input type="text" id="clat" name="clat" />

<label for="clng">Longitude:</label>
<input type="text" id="clng" name="clng" />

<label for="cacc">Accuracy</label>
<input type="text" id="cacc" name="cacc" />

<input type="hidden" data-decoder="clat" type="text" name="clat" id="latitude" readonly />
<input type="hidden" data-decoder="clng" type="text" name="clng" id="longitude" readonly />
</section>

</div>


<script>
function initMap() {
  var mapLink = $("#mapLink");
  var log = $("#log");
  var watchID;

  $("#startWatchButton").click(function()
   {
    watchID = navigator.geolocation.watchPosition(showPosition, positionError);
   }
  );

  $("#clearWatchButton").click(function()
   {
    navigator.geolocation.clearWatch(watchID);
    logMsg("Stopped watching for location changes.");
   }
  );

  function showPosition(position) {

   logMsg("Showing current position.");

   var coords = position.coords;

   $("#clat").val(coords.latitude);
   $("#clng").val(coords.longitude);

   $("#cacc").val(coords.accuracy);

   var clat = latitude.dataset.decoder;
   var clng = longitude.dataset.decoder;

   clat.value = position.coords.latitude;
   clng.value = position.coords.longitude;

    var clat=$("#clat").val(coords.latitude);
    var clng=$("#clng").val(coords.longitude);
   window.location="test-1.php?clat="+ clat.val() + "&clng="+ clng.val();
  }

  function positionError(e) {
   switch (e.code) {
    case 0:
     logMsg("The application has encountered an unknown error while trying to determine your current location. Details: " + e.message);
     break;
    case 1:
     logMsg("You chose not to allow this application access to your location.");
     break;
    case 2:
     logMsg("The application was unable to determine your location.");
     break;
    case 3:
     logMsg("The request to determine your location has timed out.");
     break;
   }
  }

  function logMsg(msg) {
   log.append("<li>" + msg + "</li>");
  }

  mapLink.hide();

}
</script>
4

0 回答 0