Google 映射通用跨平台语法 link 使用 Android 移动设备从 Chrome 打开时不初始化地址
Google maps universal cross-platform syntax link doesn't initialize adresses when opening from Chrome using a Android mobile device
在带有 Ionic5 的 Angular8 应用程序中,我使用 link 打开 Google 地图导航,其中初始化了多个地址。
我按照官方文档构建了URL,如下所述:
https://developers.google.com/maps/documentation/urls/guide
我打开 url 的函数如下所示:
export interface ILatLong {
latitude: number;
longitude: number;
}
export interface IFromTo {
from: ILatLong;
to: ILatLong;
}
export interface IRoute {
fromTo: IFromTo;
stopovers: ILatLong[];
}
export const openFullRouteMaps = (navRoute: IRoute) => {
const waypoints = (stops: ILatLong[]) => {
if (stops) {
let waypointsChained = '&waypoints=';
for (const stop of stops) {
waypointsChained += `${stop.latitude}%2C${stop.longitude}%7C`;
}
// clean up last 3 unused characters ("%7C")
return waypointsChained.slice(0, -3);
} else {
return '';
}
};
const win = window.open(
`https://google.com/maps/dir/?api=1
&origin=${navRoute.fromTo.from.latitude}%2C${navRoute.fromTo.from.longitude}
&destination=${navRoute.fromTo.to.latitude}%2C${navRoute.fromTo.to.longitude}
${waypoints(navRoute.stopovers)}`
);
return win.focus();
};
使用 Chome 从 PC、IOS 移动设备完美运行(打开 Google 地图网站或应用程序,如果可用,地址已初始化),但是当我使用 Android 移动设备时(还有 Chrome 浏览器)它会打开 Google 地图应用程序,其中没有任何地址。
有人知道哪里出了问题吗?
向 URL 添加另一个可选参数解决了我的问题:
&travelmode=驾驶
在带有 Ionic5 的 Angular8 应用程序中,我使用 link 打开 Google 地图导航,其中初始化了多个地址。
我按照官方文档构建了URL,如下所述:
https://developers.google.com/maps/documentation/urls/guide
我打开 url 的函数如下所示:
export interface ILatLong {
latitude: number;
longitude: number;
}
export interface IFromTo {
from: ILatLong;
to: ILatLong;
}
export interface IRoute {
fromTo: IFromTo;
stopovers: ILatLong[];
}
export const openFullRouteMaps = (navRoute: IRoute) => {
const waypoints = (stops: ILatLong[]) => {
if (stops) {
let waypointsChained = '&waypoints=';
for (const stop of stops) {
waypointsChained += `${stop.latitude}%2C${stop.longitude}%7C`;
}
// clean up last 3 unused characters ("%7C")
return waypointsChained.slice(0, -3);
} else {
return '';
}
};
const win = window.open(
`https://google.com/maps/dir/?api=1
&origin=${navRoute.fromTo.from.latitude}%2C${navRoute.fromTo.from.longitude}
&destination=${navRoute.fromTo.to.latitude}%2C${navRoute.fromTo.to.longitude}
${waypoints(navRoute.stopovers)}`
);
return win.focus();
};
使用 Chome 从 PC、IOS 移动设备完美运行(打开 Google 地图网站或应用程序,如果可用,地址已初始化),但是当我使用 Android 移动设备时(还有 Chrome 浏览器)它会打开 Google 地图应用程序,其中没有任何地址。
有人知道哪里出了问题吗?
向 URL 添加另一个可选参数解决了我的问题:
&travelmode=驾驶