所以我試圖讓使用PHP的座標之間的距離。 我使用這兩個功能:獲得兩個座標之間的距離公里
- 通過IP
- 定位用戶獲得與GPS圖像座標
,並把它們放在$ LAT1和$ lon1
$ip = $_SERVER['REMOTE_ADDR'];
$details = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));
$user_location = $details->loc;
$pieces = explode(",", $user_location);
$lat1 = $pieces[0];
$lon1 = $pieces[1];
$unit = "Km";
中獲取圖像我我選擇了行,他們都包含從EXIF的經度和緯度。
function get_image($db){
$select = "id, image_name";
$sql = "SELECT $select FROM images ORDER BY id DESC";
$stmt = $db->prepare($sql);
$stmt->execute();
$spot = $stmt->fetchAll(PDO::FETCH_ASSOC);
if(!$stmt -> rowCount()){
echo "<div class='noSpots'>
<p>Sorry there seams to be nothing in your area</p>
</div>";
}
return $spot;
}//spots_narrow ends here
所以在這兩個函數後,我現在可以返回四個變量與我想要計算兩個緯度和經度之間的距離。
- $ lat1
- $ lon1
- $ lat2
- $ lon2
https://developers.google.com/maps/articles/phpsqlsearch_v3請參閱'使用MySQL查找位置' – chris85