First, there's the AJAX API property that provides a simple way to get an approximate, region-level estimate of a user's location based on their IP address. It's as simple as referencing google.loader.ClientLocation
, which is made available using the Google AJAX API Loader. This API does not require users to install any client-side software. You can see this new AJAX API in action as part of the 2008 US Election gadget -- the "News by State" will show local news for the state associated with the user's IP.
Second, the Gears Geolocation API provides a way to get a more precise estimate of a user's location. On mobile devices with Gears installed, the Geolocation API can use the cell-ID of nearby cell towers or on-board GPS (if either is available) to improve the postion fix. In the near future, we'll be adding data from your WiFi connection to improve accuracy even further, on both desktop and mobile. In all cases, Gears takes care of assimilating the results from each source and returning the best available position estimate.
The Geolocation API has two JavaScript methods: getCurrentPosition()
makes a single, one-off attempt to get a position fix, while watchPosition()
watches the user's position over time, and provides an update whenever the position changes. Both methods allow you to configure which sources of location information are used. Gears also keeps track of the best position fix obtained from these calls and makes it available as the lastPosition
property. This is a simple way to get an approximate position fix with low cost in terms of both network and battery resources.
The privacy of users' location information is extremely important. The first time your site calls the Geolocation API to request a user's location, that user will be shown a permissions dialog where they can choose to allow or deny your site access. Users can change that decision at any time via the "Gears settings" dialog in the browser menu. Google does not keep location information about users when your site uses the Geolocation API.
To use the Geolocation API your users may need to install the Gears browser plugin, a simple process on both desktop and mobile. The Geolocation API is available on platforms currently supported by Gears, including Internet Explorer, Firefox and IE Mobile (selected devices only). For users to be able to use location-enabled features on mobile they will need a Windows Mobile device that supports GPS or cell-ID lookup (for example the Samsung BlackJack II and the HTC Touch Dual, see list of supported device models in our FAQ). We are working hard to bring Gears to more mobile platforms soon. You can download and install Gears at gears.google.com. Or try out some of the first location-enabled mobile web apps using Gears.
Like the rest of Gears, this new Geolocation API is open source. We're also doing our best to work with existing and emerging standards. Gears now implements the current editor's draft of the W3C Geolocation specification, which we've helped to define in collaboration with Microsoft, Mozilla, and others. We're committed to continued collaboration around the emerging HTML5 standard and the APIs specified by the W3C Web Applications Working Group. The goal for Gears is to advance browser capabilities, and part of that is helping define future web standards.
If you're interested in providing feedback or contributing to Gears, there's more info on the project website. There's also an AJAX APIs discussion group -- we're anxious to hear what you think.
The 'AJAX API property' link seems to be incorrect.
ReplyDeleteFixed. Good catch, Cheeaun. Thanks!
ReplyDeleteWe’ve had the capability for over a year now. Any app can access any native (mobile) device information and send that to a Web server. We also have the capability to allow JavaScript to access local API's from the browser (Windows Mobile) without requiring an external API.
ReplyDeleteMore information and demonstrations can be found on our web site at www.5o9inc.com and www.5o9mm.com
what if i want to do a server-side validation of the user location?
ReplyDeleteis there any webservice also available?
Sure. Go to www.5o9inc.com and look under demos for examples of it working. One is real time GPS enabled search inside the mobile browser. We mash out to a local search engine, but it could go to any search engine.
ReplyDelete很好很强大!
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis is a step in the right direction, however using IPs for geo-location will be very unreliable until there's regulation that forces ISPs to keep their databases up to date (after 8 months of service my home IP is still assigned to NJ although I am in San Diego!).
ReplyDeleteAt the beginning, Google Geolocation API has determined the location for only Americans, for the other it has returned "unknown". Later this service was advanced, but it often does not show results even for developed countries as yet. For such cases, there is a simple javascript extension to the Google API, which gives back the country of user.
ReplyDeletehttp://www.wipmania.com/en/blog/google-geolocation-api/
This comment has been removed by a blog administrator.
ReplyDeleteIs there any server side solution for this?
ReplyDeleteor a way to access this service on server side?
Yes. The commercial version of the solution supports real time data encryption so we use a server side module (based off mod_gzip which we invented) to do the decryption.
ReplyDeleteRemember this is not a service. You install the server module on your server and interact with your customers via the mobile thin client.
Accessing the data on the server is easy. It arrives as a CGI environment variable
The main 'AJAX API property' link destination appears to be gone. Does that mean the Google AJAX API method is no longer supported?
ReplyDeleteGeolocation API fully support on Mozilla Firefox.
ReplyDeleteUsing
navigator.geolocation.getCurrentPosition(function(location){
var newLocation = location.address.city + ", " + location.address.country;
alert(newLocation);
});
For Opera & Chrome it only returns latitude & longitude.
var lat = location.coords.latitude;
var lng = location.coords.longitude;