Reputation: 11
I have a J2EE web based application which is especially developed for iPad, iPhone and other mobile devices. I need to find out the device current location longitude and latitude. I done this through javaScript navigator object like below.
var gps = navigator.geolocation; if (gps){ gps.getCurrentPosition(successFunction,errorFunction, options); }
But its asking for user acceptance. Is there any way to find out the current location details using java for web application.
Upvotes: 1
Views: 1578
Reputation: 15623
In a web application, you can use some web service to discover user's approximate location from their IP address. One such free service is http://freegeoip.appspot.com/. Its URL format is http://freegeoip.appspot.com/data-format/your-ip-address. For example, if you send an http request http://freegeoip.appspot.com/json/118.13.12.116, it will send you user's city, region, country, longitude and latitude in JSON format.
Upvotes: 1
Reputation: 9150
As Aaron pointed out, if you want to get the location from on-device GPS, then you will have to accept the fact that the device will ask for user acceptance, no way around that.
For mobile phones, it is also possible to get the approximate location from mobile network (e.g. from GMLC over MLP) but:
Upvotes: 1