# 兩點座標的直線距離

```php
    /**
     * 計畫兩個座標的直線距離
     * @param  [string] $lng1 [使用者所在位置經度]
     * @param  [string] $lat1 [使用者所在位置緯度]
     * @param  [string] $lng2 [附近店家經度]
     * @param  [string] $lat2 [附近店家緯度]
     * @return [string]       [兩點距離]
     */
    function getdistance($lng1,$lat1,$lng2,$lat2){
        //將角度轉換為弧度
        $radLat1=deg2rad($lat1);
        $radLat2=deg2rad($lat2);
        $radLng1=deg2rad($lng1);
        $radLng2=deg2rad($lng2);
        $a=$radLat1-$radLat2;
        $b=$radLng1-$radLng2;
        $s=2*asin(sqrt(pow(sin($a/2),2)+cos($radLat1)*cos($radLat2)*pow(sin($b/2),2)))*6378.137;//6378.137為地球的半徑
        return $s;
    }
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tobyisme.gitbook.io/php/liang-dian-zuo-biao-de-zhi-xian-ju-li.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
