Google 地图 loadGeoJSON getGeometry.get() latlng 消失
Google Maps loadGeoJSON getGeometry.get() latlng disappear
正在学习来自 Google 的本教程:https://developers.google.com/codelabs/maps-platform/google-maps-simple-store-locator
Github 代码在这里:https://github.com/googlecodelabs/google-maps-simple-store-locator
文件:app.js
函数:initMap(), calculateDistances();
我的具体问题是 latlng 属性在某处丢失了。地图加载和所有地图点加载。但是,当我使用 search/autocomplete 时,map.data 作为参数通过此函数传递(第 218 行)
const rankedStores = await calculateDistances(map.data, originLocation);
并使用此函数解析(第 234 行)
async function calculateDistances(data, origin) {
const stores = [];
const destinations = []
// Build parallel arrays for the store IDs and destinations
data.forEach((store) => {
const storeNum = store.getProperty('storeid');
const storeLoc = store.getGeometry().get();
console.log(storeLoc);
stores.push(storeNum);
destinations.push(storeLoc);
});
在 console.log 中没有出现任何几何图形。对象和各自的 latlng 属性只是没有实际坐标。当我在控制台中查看 storeNum 时。他们按应有的方式显示。我已验证 jSON 中存在坐标,并且它们的映射点证明 map.data.loadGeoJSON 工作正常。我正疯狂地试图找到坐标的去向以及如何确保它们被传递给 calculateDistances 函数。感谢任何帮助。
截图A:
屏幕截图 B:
要从 google.maps.LatLng object (which is what is returned by store.getGeometry().get()) 检索坐标,请使用 .lat()
函数获取纬度,使用 .lng()
函数获取经度,或使用 .toUrlValue()
函数获取逗号包含两者的分隔字符串。
async function calculateDistances(data, origin) {
const stores = [];
const destinations = []
// Build parallel arrays for the store IDs and destinations
data.forEach((store) => {
const storeNum = store.getProperty('storeid');
const storeLoc = store.getGeometry().get();
console.log(storeLoc.toUrlValue(6));
stores.push(storeNum);
destinations.push(storeLoc);
});
正在学习来自 Google 的本教程:https://developers.google.com/codelabs/maps-platform/google-maps-simple-store-locator
Github 代码在这里:https://github.com/googlecodelabs/google-maps-simple-store-locator
文件:app.js 函数:initMap(), calculateDistances();
我的具体问题是 latlng 属性在某处丢失了。地图加载和所有地图点加载。但是,当我使用 search/autocomplete 时,map.data 作为参数通过此函数传递(第 218 行)
const rankedStores = await calculateDistances(map.data, originLocation);
并使用此函数解析(第 234 行)
async function calculateDistances(data, origin) {
const stores = [];
const destinations = []
// Build parallel arrays for the store IDs and destinations
data.forEach((store) => {
const storeNum = store.getProperty('storeid');
const storeLoc = store.getGeometry().get();
console.log(storeLoc);
stores.push(storeNum);
destinations.push(storeLoc);
});
在 console.log 中没有出现任何几何图形。对象和各自的 latlng 属性只是没有实际坐标。当我在控制台中查看 storeNum 时。他们按应有的方式显示。我已验证 jSON 中存在坐标,并且它们的映射点证明 map.data.loadGeoJSON 工作正常。我正疯狂地试图找到坐标的去向以及如何确保它们被传递给 calculateDistances 函数。感谢任何帮助。
截图A:
屏幕截图 B:
要从 google.maps.LatLng object (which is what is returned by store.getGeometry().get()) 检索坐标,请使用 .lat()
函数获取纬度,使用 .lng()
函数获取经度,或使用 .toUrlValue()
函数获取逗号包含两者的分隔字符串。
async function calculateDistances(data, origin) {
const stores = [];
const destinations = []
// Build parallel arrays for the store IDs and destinations
data.forEach((store) => {
const storeNum = store.getProperty('storeid');
const storeLoc = store.getGeometry().get();
console.log(storeLoc.toUrlValue(6));
stores.push(storeNum);
destinations.push(storeLoc);
});