Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
npm
/
glsx-map-sdk
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 14bee6f5
authored
Jul 05, 2023
by
李伟康
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
新增路线规划 & 输入提示
1 parent
af0b376b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
7 deletions
src/index.js
src/index.js
View file @
14bee6f
...
@@ -20,7 +20,7 @@ class GlMapApi {
...
@@ -20,7 +20,7 @@ class GlMapApi {
* @param {*} type 0:直线距离 , 1:驾车导航距离(仅支持国内坐标) , 3:步行规划距离(仅支持5km之间的距离)
* @param {*} type 0:直线距离 , 1:驾车导航距离(仅支持国内坐标) , 3:步行规划距离(仅支持5km之间的距离)
* @returns {Promise<{elements: Array}>}
* @returns {Promise<{elements: Array}>}
*/
*/
async
calculateDistance
(
from
,
to
,
type
=
1
)
{
async
calculateDistance
(
from
,
to
,
type
=
1
)
{
try
{
try
{
const
destination
=
JSON
.
parse
(
JSON
.
stringify
(
from
)).
reverse
().
join
(
','
),
const
destination
=
JSON
.
parse
(
JSON
.
stringify
(
from
)).
reverse
().
join
(
','
),
origins
=
JSON
.
parse
(
JSON
.
stringify
(
to
)).
reverse
().
join
(
','
),
origins
=
JSON
.
parse
(
JSON
.
stringify
(
to
)).
reverse
().
join
(
','
),
...
@@ -39,11 +39,11 @@ class GlMapApi {
...
@@ -39,11 +39,11 @@ class GlMapApi {
/**
/**
* 批量距离计算(矩阵)
* 批量距离计算(矩阵)
* @param {*} from 起始位置 [lat,lng]
* @param {*} from 起始位置 [lat,lng]
* @param {*} toList
重
点位置 [[lat,lng],[lat,lng]]
* @param {*} toList
终
点位置 [[lat,lng],[lat,lng]]
* @param {*} type 直线距离 , 1:驾车导航距离(仅支持国内坐标) , 3:步行规划距离(仅支持5km之间的距离)
* @param {*} type 直线距离 , 1:驾车导航距离(仅支持国内坐标) , 3:步行规划距离(仅支持5km之间的距离)
* @returns {Promise<{rows: Array}>}
* @returns {Promise<{rows: Array}>}
*/
*/
async
calculateDistanceMatrix
(
from
,
toList
,
type
=
1
)
{
async
calculateDistanceMatrix
(
from
,
toList
,
type
=
1
)
{
try
{
try
{
const
destination
=
JSON
.
parse
(
JSON
.
stringify
(
from
)).
reverse
().
join
(
','
),
const
destination
=
JSON
.
parse
(
JSON
.
stringify
(
from
)).
reverse
().
join
(
','
),
origins
=
JSON
.
parse
(
JSON
.
stringify
(
toList
))
origins
=
JSON
.
parse
(
JSON
.
stringify
(
toList
))
...
@@ -72,7 +72,7 @@ class GlMapApi {
...
@@ -72,7 +72,7 @@ class GlMapApi {
* @param {*} address (String)
* @param {*} address (String)
* @returns
* @returns
*/
*/
geocoder
(
address
)
{
geocoder
(
address
)
{
return
this
.
request
.
get
(
'/v3/geocode/geo'
,
{
return
this
.
request
.
get
(
'/v3/geocode/geo'
,
{
address
address
})
})
...
@@ -82,7 +82,7 @@ class GlMapApi {
...
@@ -82,7 +82,7 @@ class GlMapApi {
* @param {*} location [lat<纬度>,lng<经度>]
* @param {*} location [lat<纬度>,lng<经度>]
* @returns
* @returns
*/
*/
async
detailedAdrress
(
location
)
{
async
detailedAdrress
(
location
)
{
try
{
try
{
const
[
lat
,
lng
]
=
location
const
[
lat
,
lng
]
=
location
const
{
regeocode
}
=
await
this
.
request
.
get
(
'/v3/geocode/regeo'
,
{
const
{
regeocode
}
=
await
this
.
request
.
get
(
'/v3/geocode/regeo'
,
{
...
@@ -134,7 +134,7 @@ class GlMapApi {
...
@@ -134,7 +134,7 @@ class GlMapApi {
* IP定位
* IP定位
* @returns
* @returns
*/
*/
getLocationByIp
()
{
getLocationByIp
()
{
return
this
.
request
.
get
(
'/v3/ip'
)
return
this
.
request
.
get
(
'/v3/ip'
)
}
}
/**
/**
...
@@ -147,7 +147,7 @@ class GlMapApi {
...
@@ -147,7 +147,7 @@ class GlMapApi {
autonavi(不进行转换))
autonavi(不进行转换))
* @returns
* @returns
*/
*/
translate
(
locationsList
,
coordsys
=
'autonavi'
)
{
translate
(
locationsList
,
coordsys
=
'autonavi'
)
{
// 使用数组解构和map方法,将locationsList参数转换为字符串,并反转数组顺序,然后用竖线连接,得到locations字符串
// 使用数组解构和map方法,将locationsList参数转换为字符串,并反转数组顺序,然后用竖线连接,得到locations字符串
const
locations
=
JSON
.
parse
(
JSON
.
stringify
(
locationsList
))
const
locations
=
JSON
.
parse
(
JSON
.
stringify
(
locationsList
))
.
map
(
e
=>
(
e
=
e
.
reverse
()))
.
map
(
e
=>
(
e
=
e
.
reverse
()))
...
@@ -158,5 +158,47 @@ class GlMapApi {
...
@@ -158,5 +158,47 @@ class GlMapApi {
coordsys
coordsys
})
})
}
}
/**
* 路线规划
* @param {*} from 起始位置 [lat,lng] 纬度前,经度后
* @param {*} to 终点位置 [lat,lng] 纬度前,经度后
* @param {*} type 出行类型 1步行 2骑车 3驾车
*/
async
routePlanning
(
from
,
to
,
type
=
3
)
{
const
funName
=
{
1
:
'/v3/direction/walking'
,
2
:
'/v4/direction/bicycling'
,
3
:
'/v3/direction/driving'
}[
type
],
origin
=
JSON
.
parse
(
JSON
.
stringify
(
from
)).
reverse
().
join
(
','
),
destination
=
JSON
.
parse
(
JSON
.
stringify
(
to
)).
reverse
().
join
(
','
)
try
{
const
{
route
}
=
await
this
.
request
.
get
(
funName
,
{
origin
,
destination
})
return
Promise
.
resolve
(
route
)
}
catch
(
error
)
{
return
Promise
.
reject
(
error
)
}
}
/**
* 输入提示
* @param {*} keywords 查询关键词
* @param {*} location 定位坐标 [lat,lng] 纬度前,经度后
*/
async
keywordSearch
(
keywords
,
location
)
{
try
{
const
{
route
}
=
await
this
.
request
.
get
(
'/v3/assistant/inputtips'
,
{
keywords
,
location
:
JSON
.
parse
(
JSON
.
stringify
(
location
)).
reverse
().
join
(
','
)
})
return
Promise
.
resolve
(
route
)
}
catch
(
error
)
{
return
Promise
.
reject
(
error
)
}
}
}
}
export
default
GlMapApi
export
default
GlMapApi
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment