我想通過地理定位來重定向重定向和我嘗試用這個javascript函數,它工作正常:開關情況下,通過地理位置的經緯度
function showPosition(pos)
{
if (pos.coords.latitude >= 10.4696404 && pos.coords.longitude <= -66.8037185)
{
window.location = 'http://www.website.com/page1.html';
}
else{
window.location = 'http://www.website.com/page2.html';
}
}
但是當我嘗試使用一個開關的情況下不工作,有什麼這裏錯了嗎?
function showPosition(pos)
{
var lat = position.coords.latitude;
var lon = position.coords.longitude;
switch(lat + "|" + lon){
case lat >="10.4696404"|lon <="-66.8037185"://Caracas
window.location = 'http://www.website.com/page1.html';
break;
case lat >="10.0618663"|lon <="-69.3628479"://BARQUISIMETO
window.location = 'http://www.website.com/page2.html';
break;
case lat >="10.6335502"|lon <="-71.6769433": //MARACAIBO
window.location = 'http://www.website.com/page3.html';
break;
default
window.location = 'http://www.website.com/';
}
}
請告訴我的錯誤? – 2015-02-09 19:51:11
難道你會比較一個數字在第一個例子和一個字符串在第二個?緯度和經度是弦還是數字? – vanchagreen 2015-02-09 20:08:14
您好緯度和很多是地理位置的價值其lat = 10.4696404和lon = -66.8037185 – 2015-02-10 11:54:22