Page 1 of 1

GeoIP redirection

Posted: Thu Jun 26, 2014 7:32 am
by S-Jack
Hello,

I am looking at doing location to page redirect so if you're from the UK you will get the number 123 and if you're from the US then you'll get 987 but I can't seem to get the hang of it.

Could someone please point me in the right direction? (The code I've got is below)

Code: Select all

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>removed</title>
<script type='text/javascript'>//<![CDATA[ 
window.onload=function(){

    if(navigator.geolocation)
    {
    navigator.geolocation.getCurrentPosition(showPosition,showError);
    }
    else
    {
    alert("Geolocation is not supported by this browser.");
    }
    
    function showError(error)
      {
      switch(error.code)
        {
        case error.PERMISSION_DENIED:
          alert("User denied the request for Geolocation.");
          break;
        case error.POSITION_UNAVAILABLE:
          alert("Location information is unavailable.");
          break;
        case error.TIMEOUT:
          alert("The request to get user location timed out.");
          break;
        case error.UNKNOWN_ERROR:
          alert("An unknown error occurred.");
          break;
        }
      }

 function showPosition(pos)
  {
 
   if (pos.coords.longitude >= 55.378051 && pos.coords.longitude <= -3.435973 && pos.coords.latitude <= 37.090240 && pos.coords.latitude >= -95.712891)
        {
            alert("987");
		//window.location = 'USD/';
        }
        else{
            alert("123");
           // window.location = 'GBP/';
        }
  }
}//]]>  
</script>
</head>
<body>
</body>
</html>

Re: GeoIP redirection

Posted: Thu Jun 26, 2014 1:26 pm
by requinix

Code: Select all

pos.coords.longitude >= 55.378051 && pos.coords.longitude <= -3.435973
Can you think of a number that is larger than 55 and less than -3? I can't.

I'm not sure where you're getting those numbers from, but when you do find the right ones, the only issue with a direct comparison would be the international time line at longitude 180/-180. If you needed something there you couldn't do (for example) >170 and <-170. Instead you'd need (>170 or <-170).

Re: GeoIP redirection

Posted: Thu Jun 26, 2014 2:39 pm
by S-Jack
requinix wrote:

Code: Select all

pos.coords.longitude >= 55.378051 && pos.coords.longitude <= -3.435973
Can you think of a number that is larger than 55 and less than -3? I can't.

I'm not sure where you're getting those numbers from, but when you do find the right ones, the only issue with a direct comparison would be the international time line at longitude 180/-180. If you needed something there you couldn't do (for example) >170 and <-170. Instead you'd need (>170 or <-170).
Hello,

I've tried them the other way round ( if (pos.coords.longitude >= -3.435973 && pos.coords.longitude <= 55.378051 & ) and it still doesn't do it.

Re: GeoIP redirection

Posted: Thu Jun 26, 2014 3:36 pm
by requinix
Did you correct the numbers? Because they're way off.

* 3.43W 37.09N is in Spain
* 55.38E 37.09N is in Iran
* 95.7S does not exist