Search code examples
phpandroidmobilegeolocation

PHP Get Mobile Devices Location?


I am wondering if there is a way to get the current location from a mobile device in PHP? By current location I mean the last known location.

Thanks for any help!


Solution

  • HTML5 includes an extended JavaScript API that can help, geolocation is one of them, problem is that some browsers do not support it 100%, Firefox doing the best job. This how you would use it, after that you would pass values to PHP via AJAX.

    if(navigator.geolocation)
    {
      navigator.geolocation.getCurrentPosition(function(position)
        {
          var lat = position.coords.latitude;
          var lng = position.coords.longitude;
          doSomething();
    
        });
    }