> For the complete documentation index, see [llms.txt](https://noel77543.gitbook.io/ztool/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://noel77543.gitbook.io/ztool/tool/sensor/zlocationtool.md).

# ZLocationTool

#### CallBack

```java

/***
* 持續監聽用
**/
public interface OnLocationChangeListener {
    //當取得位置資訊
    void onLocationChanged(Location location);

    //當連線中段
    void onSuspended(int i);

    //GoogleLocationAPI連線失敗
    void onFailed(ConnectionResult connectionResult,int errorCode);

}

//-----------

/***
* 單次監聽用
**/
public interface OnLocationGetListener {

    //當取得位置資訊
    void onLocationGet(Location location);

    //當連線中段
    void onSuspended(int i);

    //GoogleLocationAPI連線失敗
    void onFailed(ConnectionResult connectionResult,int errorCode);
}
```

**---**

**PUBLIC METHOD**

```java
 /***
     *  前者至後者的直線距離 單位公尺
     * @param location1
     * @param location2
     * @return
     */
    public float getStraightDistance(Location location1, Location location2) 

    //-------------

    /***
     *  取得基於poly line 線條的起點至終點距離  單位公尺
     */
    public float getPolyLineDistance(Polyline polyline) 

    //--------------------

    /***
     *  取得目前裝置所在經緯度
     */
    public void setCurrentLocationListener(OnLocationGetListener onLocationGetListener) 
    //--------------------

    /***
     * 持續監聽目前所在位置
     */
    public void setCurrentLocationChangeListener(OnLocationChangeListener onLocationChangeListener)
    
    //---------------------
    
    /***
     *  移除經位度取得工具
     *  一般在controller的onResume設置持續監聽器
     *  在onPause的時候clear
     */
    public void clear()
    
```
