2 回答

TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超5個(gè)贊
您可以在起始頁(yè)面的 PWA 中調(diào)用以下代碼。這樣每次用戶通過(guò)點(diǎn)擊您提供的鏈接打開它時(shí),應(yīng)用程序都會(huì)獲得她/他的位置:
function getLocation() {
// Check if the current device support geoLocation
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(pos) {
console.log("Latitude: " + pos.coords.latitude +
"Longitude: " + pos.coords.longitude);
});
} else {
// Geolocation is not supported by the
}
}
這里是關(guān)于 Gelocation的MSDN 文檔。

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超9個(gè)贊
你必須使用web worker。
Web Worker 是在后臺(tái)運(yùn)行的 JavaScript,獨(dú)立于其他腳本,不會(huì)影響頁(yè)面的性能。你可以繼續(xù)做任何你想做的事情:點(diǎn)擊、選擇東西等,而 web worker 在后臺(tái)運(yùn)行。
現(xiàn)在的PWA使用服務(wù)工作者(一種網(wǎng)絡(luò)工作者)來(lái)獲取通知,即使在應(yīng)用程序關(guān)閉時(shí)也是如此。
添加回答
舉報(bào)