提交
This commit is contained in:
1 parent
33c038b8d9
commit
54b27a3f0e
253 files changed
+30060
-14298
No files matched your search
@@ -13,6 +13,41 @@ export function buildAmapNavigationUrl(
|
||||
return `https://uri.amap.com/navigation?to=${lngText},${latText},${toName}&mode=car&coordinate=gaode&callnative=1`
|
||||
}
|
||||
|
||||
/** 构建高德 URI 标记点链接(Web/App 查看位置) */
|
||||
export function buildAmapMarkerUrl(
|
||||
lng?: number | null,
|
||||
lat?: number | null,
|
||||
name?: string
|
||||
): string | null {
|
||||
if (lng == null || lat == null || Number.isNaN(Number(lng)) || Number.isNaN(Number(lat))) {
|
||||
return null
|
||||
}
|
||||
const lngText = Number(lng).toFixed(6)
|
||||
const latText = Number(lat).toFixed(6)
|
||||
const markerName = encodeURIComponent((name || '位置').trim() || '位置')
|
||||
return `https://uri.amap.com/marker?position=${lngText},${latText}&name=${markerName}&coordinate=gaode&callnative=0`
|
||||
}
|
||||
|
||||
/** 按地址关键词打开高德地图搜索(无坐标时的兜底) */
|
||||
export function buildAmapSearchUrl(keyword?: string | null): string | null {
|
||||
const text = keyword?.trim()
|
||||
if (!text) return null
|
||||
return `https://www.amap.com/search?query=${encodeURIComponent(text)}`
|
||||
}
|
||||
|
||||
/** 优先坐标标记,否则按地址搜索 */
|
||||
export function buildAmapLocationUrl(options: {
|
||||
lng?: number | null
|
||||
lat?: number | null
|
||||
name?: string
|
||||
address?: string
|
||||
}): string | null {
|
||||
return (
|
||||
buildAmapMarkerUrl(options.lng, options.lat, options.name || options.address) ||
|
||||
buildAmapSearchUrl(options.address || options.name)
|
||||
)
|
||||
}
|
||||
|
||||
export function appendAmapNavLine(lines: string[], label: string, url: string | null) {
|
||||
if (url) {
|
||||
lines.push(`${label}:${url}`)
|
||||
|
||||
Reference in new issue
Block a user