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.
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.
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
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!!
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.
精彩评论