Lam George
Lam George

Reputation: 11

how identify geographical location and redirect in particular page with php?

I would like to ask, how I can identify geographical location and redirect the user in their geographic web page using php. I know the redirection is like.

<?php
header('Location: mypage.php');
?>

I appreciate for your help

Upvotes: 0

Views: 505

Answers (1)

Akash Kumar
Akash Kumar

Reputation: 642

<html>

<head>
<script src="http://maps.google.com/maps/api/js?sensor=true" type="text/javascript"></script>
<script type="text/javascript">

if (navigator.geolocation) { 

        navigator.geolocation.getCurrentPosition(function(position) {  

        var lat = position.coords.latitude;
        var lng = position.coords.longitude;

        var latlng = new google.maps.LatLng(lat, lng);

    var geocoder = new google.maps.Geocoder();

geocoder.geocode({'latLng': latlng}, function(results, status) {
  if (status == google.maps.GeocoderStatus.OK) {
    if (results[1]) {
    alert(results[7].formatted_address);
    }
  } else {
    alert("Geocoder failed due to: " + status);
  }
});
      });
      } else {
        alert("Geolocation services are not supported by your browser.");
} 

</script>
</head>
<body>
</body>
</html>

Using this you can get Coordinates of place and then using Google API you can have country code and accordingly you can send user to particular page

Upvotes: 2

Related Questions