I was reading an InfoWorld article on the benefits and features of HTML version 5, which isn’t a formal standard yet, but many elements of which are already incorporated into browsers.
Media: A major benefit for all of us will be that embedding media (videos particularly) will become standardized and greatly simplified, so the web developer won’t have to worry so much about plug-ins, players and compatibility.
Geo-location: But more fun perhaps than that, there is a geo-location feature built into HTML5, and it’s available today on some browsers (Chrome, Safari, Firefox). In this article Dive into HTML5 — You are here (and so is everybody else), there’s a cookbook for creating a web page that locates you and displays a Google map centered on your coordinates. My page will figure out where you are located and display the Google map — but only if you have an HTML5-compliant browser, sorry. Mobile browsers are particularly good for this because they know your location quite precisely.
I took an hour this morning to build the page, and subject to some debugging (and figuring out that the whole process is asynchronous), I had it working. Clearly if you’re at a wired location, Google is using your IP address and maybe some routing information to locate “approximately” where you are, but on my iPhone it gets much closer to the real location. I used the “You are here…” article, plus some advice from Google code.
And the interface asks you whether to reveal your location before it goes ahead and gives it to the web page to work with. Nice!
That bit about it being asynchronous is important. Anyone used to writing plain-vanilla javascript code knows that usually javascript statements are executed one after another, right down the page (as it were), and you’d think that making a function call to get the current location would actually complete the task and then return control when it finished, to execute the rest of the javascript statements. But this particular interface simply triggers the process of getting the location, and then when it has completed, it makes a callback to a javascript function where you can complete the rest of the work of putting the map up on the page (or any other thing you want to do with the location information).
This kind of asynchronous execution of statements and functions, with callback functions being given control later on when some action is completed, is common in most programming languages, but many javascript coders don’t use it very much. This is one case where you have to pay careful attention and plan ahead.
To get a better idea of how it works, look at the page I wrote and then view source to see how the javascript is written.
Now the InfoWorld article also mentions that HTML5 might not be a fully-adopted standard until 2022, which means that everyone will have blown by it long ago by then and we’ll have a hodgepodge of implementations none of which will completely match the eventual standard. Ahem! Things have to work faster than that in the online world!
Leave a Reply