这是关于php的任何解决方案吗?
更多描述:
无论如何知道到最近的海岸点的距离(即距离海的最小距离)?
提前致谢。
答案 0 :(得分:2)
请尝试
$dist = "https://maps.googleapis.com/maps/api/directions/json?key=&origin=".$lat1.",".$lon1."&destination=".$lat2.",".$lon2."&mode=driving&sensor=true";
$result_string = file_get_contents($dist);
$result = json_decode($result_string, true);
答案 1 :(得分:1)
使用此功能计算long和lat之间的距离
function distance($lat1, $lon1, $lat2, $lon2, $unit) { $theta = $lon1 - $lon2; $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); $dist = acos($dist); $dist = rad2deg($dist); $miles = $dist * 60 * 1.1515; $unit = strtoupper($unit); if ($unit == "K") { return ($miles * 1.609344); } else if ($unit == "N") { return ($miles * 0.8684); } else { return $miles; } } echo distance(32.9697, -96.80322, 29.46786, -98.53506, "M") . " Miles<br>"; echo distance(32.9697, -96.80322, 29.46786, -98.53506, "K") . " Kilometers<br>"; echo distance(32.9697, -96.80322, 29.46786, -98.53506, "N") . " Nautical Miles<br>";
答案 2 :(得分:0)
距离Coast REST API有一段距离:http://www.kbgeo.com。您提供目标纬度/经度对或街道地址,它返回到最近的沿海点的距离以及该点是什么。 JSON响应示例:
{
"distanceInMiles": 702.4893212372758,
"targetPoint": {
"lat": 43.045583,
"lng": -89.3799951
},
"coastlinePoint": {
"lat": 38.662389,
"lng": -77.236111
}
}
http://demo.kbgeo.com上有一个实时演示页面。
公开:我编写了此API,因此有既得利益。另一个具有相同功能的API是maprisk.com。