1
香港專業教育學院嘗試過一切,我知道該怎麼做(並不多TBH),所以這裏是代碼,而不試圖重定向:如果變量等於False,則通過JavaScript重定向?
if (navigator.geolocation) {
// Locate position
navigator.geolocation.getCurrentPosition(displayPosition);
} else {
alert('It seems like Geolocation, which is required for this page, is not enabled in your browser. Please use a browser which supports it.');
}
blacklisted_areas = {
'area 51': [1, 2],
'pink unicorn zoo': [1, 2],
};
// Success callback function
function displayPosition(pos) {
var mylat = pos.coords.latitude;
var mylong = pos.coords.longitude;
var thediv = document.getElementById('locationinfo');
thediv.innerHTML = '<p>Your longitude is :' + mylong + ' and your latitide is ' + mylat + '</p>';
}
var blacklisted = false;
for (let x of Object.values(blacklisted_areas)) {
if (displayPosition()[0] === x[0] && displayPosition()[1] === x[1]) {
blacklisted = true;
}
}
//Now right below here is where I need to check for blacklisted's value (if false redirect to a different site)
請幫助我:((
謝謝你,不過是它被定位不正確,目前的區域?請幫忙,因爲它什麼都不做。 –
navigator.geolocation是異步的。嘗試粘貼var blacklisted = false和displayPosition()內的所有內容() 編輯:等待一秒,您將不得不重新組織一下。讓我發表一條新評論後,我想通過這一點 –
不工作,你能詳細討論放在哪裏嗎?我在控制檯中得到一個Pos undefined錯誤 –