[TOC]
## 計算
### 計算2個坐標點之間都距離
```
$common.GetDistance(lat1, lng1, lat2, lng2);
```
## 集成定位(自動緩存,自動失敗根據IP定位)
集成定位(集成了基本定位的業務邏輯,先從系統定位獲取定位,如果獲取失敗會用IP定位,并會把定位的結果緩存)
```
$common.home_ea55_latlon(function (ret,err){
// alert(JSON.stringify(ret));
});
```
## 主動緩存定位信息
```
//緩存定位信息
$common.ea55_latlon_config({lat:'',lon:''});
```
## 獲取緩存的定位數據緩存
每次執行 $common.home_ea55_latlon 定位之后會有一個緩存,可以通用下面方法獲取
```
var config=$common.config();
alert(JSON.stringify(config.ea55_latlon));
```
*****
## 單獨定位+ip定位
```
$common.ea55_latlon({},function (ret,err){
alert(JSON.stringify(ret));
});
```
*****
## 單獨根據IP定位
```
$common.ea55_latlon_ip({},function (ret,err){
alert(JSON.stringify(ret));
});
```
## 單獨gps定位
```
$common.ea55_latlon_in({},function (ret,err){
alert(JSON.stringify(ret));
});
```
*****
## 地圖選擇
```
$common.ditu({
title:'',//標題
central_lat:'',//中心點
central_lon:'',//中心點
only_in_circle:false,//是否只能選擇圈內坐標
mapScopeType:false,//1:圓形,2:多邊形 圓形是以中心點(longitude,latitude)和區域半徑(radiusRange),多邊形以多個經緯度區間areaScope
radiusRange:1000,//圓的半徑 單位:米 mapScopeType=1點時候有效
areaScope: [{"path":[[113.578262,22.800492],[113.577625,22.796883],[113.581449,22.79682],[113.582162,22.800324],[113.580478,22.800932]]},{"path":[[113.584513,22.800163],[113.583679,22.797037],[113.586805,22.796715],[113.587905,22.799757],[113.586456,22.800869]]},{"path":[[113.58404,22.805436],[113.577295,22.802133],[113.588853,22.801259]]}],//多邊形數組.支持多個
},function (ret){
// alert(JSON.stringify(ret));
});
```
## 列表模式搜索地址
```
$common.plugin_address({},function (ret){
// alert(JSON.stringify(ret));
});
```
## 高德地圖操作
### 在地圖上畫線+跳到線的中心點+自動控制縮放比例
| 參數 |描述 | 類型 |默認值 | 是否可選|
| --- | --- |--- | --- | --- |
| id | 繪制路線分配的 id ,removeRoute 時使用此 id 移除路線 | 數字 | transit | |
| auto_index | * 路線方案的索引,在 searchRoute 時返回的多個路線方案組成的數組中的索引 | 數字 | 0 | |
| type | 路線類型 取值范圍:drive(開車)transit(公交)walk(步行)ride(騎行) | 字符串 | transit | |
| strategy | 路線策略,type 為 walk(步行)或ride(騎行)時,此參數可不傳取值范圍:drive_time_first:速度優先(時間)drive_fee_first:費用優先(不走收費路段的最快道路)drive_dis_first:距離優先drive_highway_no:不走高速drive_jam_no:結合實時交通(躲避擁堵)drive_highway_fee_no:不走高速且避免收費drive_highway_jam_no:不走高速且躲避擁堵drive_fee_jam_no:躲避收費和擁堵drive_highway_fee_jam_no:不走高速且躲避收費和擁堵transit_time_first:最快捷模式transit_fee_first:最經濟模式transit_transfer_first:最少換乘模式transit_walk_first:最少步行模式transit_comfort_first:最舒適模式transit_subway_no:不乘地鐵模式 | 字符串 | drive_time_first/transit_time_firs | |
|start | 起點信息 :{ lon: 116.403838, lat: 39.914437 } | JSON 對象 | | |
|end | 終點信息 :{ lon: 116.403838, lat: 39.914437 } | JSON 對象 | | |
|waypoints | 途經點信息組成的數組,僅當 type 為 drive 時有效 :[{ lon: 116.403838, lat: 39.914437 },{ lon: 116.403838, lat: 39.914437 }]| JSON 對象 | | |
|icons | 路線結點標注圖標 | JSON 對象 | | |
|styles_driveLine | 駕車路線的線條顏色,支持 rgb、rgba、# | 顏色值 | #24B999 | |
|styles_width | 駕車路線寬度 | 數字 | 7 | |
|auto_center | 自動跳到中心點 | 布爾值 | false | |
|auto_zoomLevel | 自動縮放等級 | 布爾值 | false | |
```
引入文件
<script src="../script/turf.min.js"></script>
$common.aMap_drawRoute({
id:10,
index:10,
auto_center:true,
auto_zoomLevel:true,
type: 'drive',
strategy:'drive_fee_first',
policy: 'drive_fee_first',
start: {
lon: 113.58283822116879,
lat:22.797983582959155
},
end: {
lon: 113.58283822116879,
lat: 22.797983582959155,
},
icons: { //(可選項)JSON對象;路線結點標注圖標
start: 'widget://image/1_1.gif', //(可選項)字符串類型;起點圖標路徑,要求本地路徑(fs://、widget://);默認:默認起點圖標
end: 'widget://image/icon/chengke.png', //(可選項)字符串類型;終點圖標路徑,要求本地路徑(fs://、widget://);默認:默認終點圖標
bus: 'widget://image/1_1.gif', //(可選項)字符串類型;公交路線結點提示圖標路徑,要求本地路徑(widget://、fs://)默認:默認公交圖標
car: 'widget://image/1_1.gif', //(可選項)字符串類型;駕車路線結點提示圖標路徑,要求本地路徑(widget://、fs://)默認:默認駕車圖標
man: 'widget://image/1_1.gif' , //(可選項)字符串類型;步行路線結點提示圖標路徑,要求本地路徑(widget://、fs://)默認:默認步行圖標
ride: 'widget://image/1_1.gif' //(可選項)字符串類型;騎行路線結點提示圖標路徑,要求本地路徑(widget://、fs://)默認:默認步行圖標
}
},function (ret){
// alert(JSON.stringify(ret));
});
```
## 打開導航軟件
```
引入文件
<script src="../script/callmap.js"></script>
ea55_fnOpenMap({
end:{
lon: lon,
lat: lat,
}
},function(ret){
});
```
## 坐標轉換成地址信息
```
$common.home_ea55_xy_to_address({
tag:'home_ea55_xy_to_address',//可選 用于重復提交中斷之前的網絡請求
lat:'22.899276',//緯度
lon:'112.029737',//經度
not_loading:false,//是否不顯示加載圈圈
},function(ret, err){
// alert(JSON.stringify(ret));
});
```
## 路線規劃
[https://lbs.amap.com/api/webservice/guide/api/direction](https://lbs.amap.com/api/webservice/guide/api/direction)
```
$common.ditu_Route_planning({
lon1:'',
lat1:'',
lon2:'',
lat2:'',
},function(ret,err){
console.log(JSON.stringify(ret));
});
```