Steven
Steven

Reputation: 13995

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!

Upvotes: 2

Views: 15155

Answers (3)

siddhant sankhe
siddhant sankhe

Reputation: 633

Php can get the mobile location(rough) if it is combined with proper API to get location of the mobile device.

http://wiki.opencellid.org/wiki/Main_Page

provides the API to get things done but for the parameters in API calling we need android device to do so.

cURL this http://opencellid.org/cell/get?key=fa83faf1-40d7-XXXX-b97eb197d0bd&mcc=260&mnc=2&lac=10250&cellid=26511&format=json

response:

{ lon: 21.011393650000002, lat: 52.2308017, mcc: 260, mnc: 2, lac: 10250, cellid: 26511, averageSignalStrength: -65, range: 34, samples: 2, changeable: true, radio: "GSM" }

Upvotes: 0

pilotstarmedia.com
pilotstarmedia.com

Reputation: 577

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();

    });
}

Upvotes: 3

Andrew - OpenGeoCode
Andrew - OpenGeoCode

Reputation: 2287

PHP is a server side scripting language. It would not have any access to your mobile phone.

From your web application running on the mobilephone, you can use the HTML5 geolocation feature to get your current (or last) GPS location in javascript. BUT, there is no guarantee that it will use the mobile phone's GPS hardware. A lot of times I only get results from cell towers or WiFi hotspots, with accuracy only about 500+ meters.

If you want to guarantee getting the actual last reading from the mobile device's GPS hardware, you will need to write a mobile application to access this information for you.

Someone asked this same question in January. See this article for more detail on answers. Mobile GPS web application

Upvotes: 0

Related Questions