4

In my HTML5 page I would like to retrieve the altitude of the device (I'm testing on my Nexus 5 with Chrome mobile).

As mentioned in HTML5 Geolocation Altitude, the altitude returned by the Geolocation API is always null.

I've read that some native Android apps use different approaches such as pressure sensor (when available). Is it somehow possible in HTML5? Do you have other suggestions?

Community
  • 1
  • 1
sdabet
  • 18,360
  • 11
  • 89
  • 158
  • is gps active on your phone ? , can you please post some HTML 5 and JavaScript code you are using to get altitude ? – bmscomp May 20 '15 at 11:31
  • The first answer to this question might be what you're looking for: [Getting Altitude of my iPhone](http://stackoverflow.com/questions/10630664/getting-altitudeheight-from-sea-level-of-my-location-in-iphone-sdk?rq=1) – Daniel Siebert May 20 '15 at 18:35

1 Answers1

1

Accessing barometer information

Sadly as of 2015 it's not possible to access barometer information in a native browser environment. A lot of work has been done on writing sensor API specifications, but as barometers are quite a rare hardware feature still they have not been receiving a lot of attention.

It is however possible to bundle your web application in Cordova and use the barometer plugin for android to access the barometer from your code. This however means that the user has to install your application and this would only work Android.

Using GPS information after all

For the large majority of applications where you need altitude information there is only one possible altitude per coordinate pair (this is for example not true if you wish to determine the level you're at in a building, but current GPS altitude information isn't precise enough for that normally either way). In those cases you can request the GPS location and simply request the altitude from a service with a surface database. Two such services are the Google Elevation API (entire world) or the NED Point Query Service (US only?).

David Mulder
  • 26,123
  • 9
  • 51
  • 114
  • Barometer measures pressure, not elevation. Barometers are used to detect (small) elevation changes and must be regularly calibrated via GPS elevation data (or via manual input of current known elevation). One could theoretically calculate the elevation with only the barometer readings, but you will also need a pressure reading of a nearby weather station at a known elevation. In other words - too complicated and (probably) too inaccurate. – alesc May 21 '15 at 11:50
  • 1
    @alesc Wasn't saying it's a *good* idea, but he was asking for it (at least, I assume that's what he meant with pressure sensor). – David Mulder May 21 '15 at 12:11