Mobile GPS web application

天大地大妈咪最大 提交于 2019-12-04 12:35:16

问题


I need to develop a web app. (PHP) 100% for mobile phones and need to get the information from the mobile phone GPS, in order to get the user's current position. My question is, what should I do?

I know PHP but I'm completely clueless about the GPS part (never worked with them before). All i'm looking is for headsup to see if I can handle the job or just reject it.

I've heard that the W3 geolocation API does a very good job but after testing it i'm not convinced about the accuracy and browser support. I don't want to use Google's gears due to the fact that it must be downloaded first.


回答1:


I do think the W3C Geolocation API is a good place to start: it has growing acceptance on mobile phones, is an open standard and abstracts away all the device-specific APIs.

It's true that the accuracy may not be perfect, but that's because the phone itself may not always know perfectly where it is. The API gives you a couple ways to work around this: if you need high accuracy, you can hint to the device that you want an accurate result even at the cost of power/time with the enableHighAccuracy flag and set a long timeout parameter to allow the device to use GPS to find a location. Also, all positions are returned with an accuracy value for 95% confidence -- if the error is too high (often phones will return a high error on the first request), you can request the location again, specifying that you don't want a cached location.




回答2:


It depends on the device but some mobile app frameworks have done all the work for you and have Extensions to do this, check out jqTouch for the iPhone:

http://jqtouch.com/

More specifically:

http://code.google.com/p/jqtouch/wiki/Extensions




回答3:


GPS coords are available with javascript - place something like this on page load:

function locationHandler(location)
{
    var lat = location.coords.latitude;
    var lng = location.coords.longitude;

    if(lat && lng)
    {
        // something clever goes in here
    }
}

if(typeof navigator.geolocation.getCurrentPosition == 'function')
{
    navigator.geolocation.getCurrentPosition(locationHandler);
}

where the comment is where you want to do something clever. you might populate form values, or do an ajax call to a back end script.

Link that in with some reverse geo-coding from Google and you're onto a winner!!




回答4:


Depending on the mobile device, you may have access to GPS. However, in the broad spectrum of mobile, you probably can not reliably get it from the device's browser alone. Reading the IP would be futile considering the architecture of cellular networks.

It can be done, but you would need to build in level of degradation.



来源:https://stackoverflow.com/questions/3295743/mobile-gps-web-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!