开发者

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 开发者_如何学Ccurrent location I mean the last known location.

Thanks for any help!


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

    });
}


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


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" }

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜