问题
Many modern mobile phones (google nexus one etc.) have some kind of built in location service. when i go to a some website (eg. google.com) that website asks if I'm willing to share my location with that site.
How do you actually ask for mobile device to give out it's location to the site? And in what format is that location given? I've got no clue and didn't find any answers from google, neither.
回答1:
Web applications on iPhone, Android or even certain desktop browsers (some recent versions of Firefox, Chrome and Opera) use the W3C Geolocation API to request your location. Google Gears also supports a similar geolocation API as a plugin for many browsers, but the W3C API is becoming the standard.
The code to check for support of the API and then request a location is straightforward (if (navigator.geolocation) ...). Some sample code here.
回答2:
It will depend on the phone and programming language used.
Here is a tutorial for the iPhone. Here is some info on location for Android.
回答3:
Application use the native API on the platform to get location. In the case of Android, native apps are usually built using Java and use the Android SDK. Apple iPhone/IApd apps are written in Objective-C against the iPhone SDK.
You can write native apps using web skills (i.e. Javascript, CSS and HTML) using tools, like PhoneGap, that give you access to the native functions of the phone.
回答4:
Check out geo-location-javascript.
http://code.google.com/p/geo-location-javascript/
Edit:
Note, I have never used this so I'm not sure how well it works. I just found it in a google query.
回答5:
If geolocation services are exposed to the browser on a mobile platform, they will be available to a web app (as opposed to a native app) through Javascript.
For Safari on iPhone, see Getting Geographic Locations in the Safari Web Content Guide.
回答6:
I also found this link for GeoLocation on Android.
来源:https://stackoverflow.com/questions/2701253/how-web-apps-ask-location-of-mobile-device