【发布时间】:2015-09-25 21:16:11
【问题描述】:
所以我正在尝试使用 php 获取坐标之间的距离。 我正在使用这两个功能:
- 通过ip定位用户
- 获取带有 GPS 坐标的图像
在通过 ip 定位用户时,我从 ip 获取纬度和经度,并将它们放入 $ 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
【问题讨论】:
-
developers.google.com/maps/articles/phpsqlsearch_v3 见
Finding Locations with MySQL