[GIS] Read position from windows tablet GPS

geoext-2gpshtml5javaopenlayers

I have a Lenovo Miix 2 tablet and I am developing a project with a Java servlet. I want to read GPS data in my project. Can I read this data using Java? and/or HTML5?

update:
In this project, I can't use the Internet to obtain the position of the user. And this is a local web application and the user views the application in a browser.

Best Answer

(This answer addresses the comments of John Barça’s comments… a little too large to put into the comments section).

Again, I got this to work using PhoneGap, but I should perhaps clarify things a little bit.

1) I used PhoneGap Build instead of installing PhoneGap on my computer (glad to have a workmate who can give me this great kind of advice!). You will not have to deal with the installation and other things, and you can just zip your entire web app and upload it to Build, which then converts it to files for either Android, iOS or Windows. You are limited to 50 MB and you can only upload one app at a time (if you are using the free version, that is; if you are willing to pay, then you have more possibilities). It works very well. You have to seriously test your app, of course, and see if some bugs might have been introduced, but if there were, then you can use remote debugging to look into what is going wrong... once you figure out how to get that set up you can debug just like using the Chrome Developer Tools, or Firebug. As a side note, my app was built using jQuery Mobile, OpenLayers, geolocation, and even offline tiles (created in TileMill, using OSM Bright, so yes, the app can be way more than just a very simple HTML file that uses some JavaScript somewhere).

2) I did not use the geolocation functions from PhoneGap but the Geolocation API in general. If you look at the details then you realize that the former is built on the latter anyways, and even the syntax looks quite similar. But generally, going the “normal” route without even looking into the PhoneGap docs works fine. If in the options object you set enableHighAccuracy to true then it will always look for the best possible way to locate the device, which, if available, is GPS. So make sure that setting is set to true (look at the link I provided and navigate to Fine tuning response). Otherwise it might look for quicker but less accurate ways to locate you (e.g., IP address, wifi triangulation, etc.), which will not work either way if you are using your app offline.

3) (this point is more of a heads up, but not entirely linked to the response) As the app should work offline you also have to find a way to get to display an offline map. If you are using PhoneGap Build then it is important that you keep the 50 MB limit in mind! Tilesets can get very large very quickly (especially if you enable the zoom levels that show the most detail)! If your area is quite small then that would be of no concern you, but if you are looking at providing tiles for anything bigger than a city, then you would almost surely hit the limit. Your options then could be to let the user cache a map when online, and use it when offline (such as the Google Maps app lets you do it), or you could add some code to your app that pulls the tiles from a specific folder on your device, and then after the app has been installed you would have to drop your tiles in that exact folder, so they can be retrieved. You could do that using PhoneGap’s File API. I have not implemented either of those options yet, but my workmate and I will be looking into them soon, as it would be awesome to benefit from the simplicity of using PhoneGap Build, but still be able to load huge tilesets.

Related Question