在Google Maps API中从Lat和Long创建一个新点

Create a new point from Lat and Long in Google Maps API

本文关键字:新点 一个 创建 Long Maps Google API 中从 Lat      更新时间:2023-09-26

我正在一个多页的应用程序工作,我在检索在一个页面中输入的坐标,并使用它来显示另一个数据面临困难。我正在对进入第一页的地址进行地理编码,并将其存储在本地缓存中。

在第二页,我使用

检索这些
var srcLat = localStorage.getItem('srcLat');
var srcLong = localStorage.getItem('srcLong');
var destLat = localStorage.getItem('destLat');
var destLong = localStorage.getItem('destLong');

我现在想求出这两个坐标之间的距离和通勤时间。有没有办法把srcLat和srcLong转换成一个叫src的点来表示这些坐标这样我就可以用这个-

displayRoute(srcPoint, destPoint, directionsService,
directionsDisplay);

如有其他解决方法,请提出建议。

PS:该应用程序是一个项目演示,因此将只在chrome上运行。因此使用本地存储

是的,你必须创建一个latLng对象,它看起来像这样

var srcPoint = {lat: srcLat, lng: srcLong}
var destPoint = {lat: destLat, lng: destLong}

该对象代表地图上的一个点。

如果您对解释什么是latLng对象的文档感兴趣,请查看这里