我正在尝试做两件事,但我自己无法做到其中之一。我想在函数中使用全局变量。我想更改所述全局变量中的一些属性。一个按钮触发'getLocation',触发'storePosition',触发'mapScreen',触发'moveMapToInitialPoint'。我正在使用 here maps API 并且我正在尝试获取用户位置并围绕它设置地图。对于问题 1,我尝试在函数内部移动变量,但是,我将在整个函数中多次使用该变量。我还尝试添加“global.”、“this.”和“globalthis.”。在变量之前。这真的很令人困惑,因为我的下一个函数能够很好地访问全局变量。对于问题 2,我尝试使用 'initialPoint[lat]' 但它说找不到 lat。我还尝试创建一个新对象,其属性设置为位置对象。我还尝试了文档中的说明以及其他堆栈问题,但它不起作用。function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(storePosition); } else { alert("Geolocation is not supported by this browser.") }}initialPoint = {lat:39.9522, lng:-75.1932};function storePosition(position) { initialPoint.lat = position.coords.latitude; initialPoint.lng = position.coords.longitude; mapScreen();}function moveMapToInitialPoint(map){ map.setCenter(initialPoint); map.setZoom(14);}moveMapToInitialPoint(map);我只想让地图围绕用户旋转,但它要么显示整个世界,因为点已损坏,要么显示默认位置。
添加回答
举报
0/150
提交
取消