-1

I want to redirect by geolocation and i try with this javascript function and it works fine:

 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';
        }
  }

but when i try to use a switch case do not work, what is wrong here?

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/';
        }
      }
puddinman13
  • 1,408
  • 4
  • 18
  • 35

1 Answers1

0

Try adding : after default:

...
  default:
    window.location = 'http://www.website.com/';
...

UPDATE:

Check the javascript switch sintax, maybe this question could help you: javascript: using a condition in switch case

Community
  • 1
  • 1
manzapanza
  • 6,087
  • 4
  • 39
  • 48