Mar 09

I love calculating driving directions on Google Maps and then drag the blue line marking my directions to change the route. Everything is updated automatically on the page and the directions are re-calculated to go through the new point I defined.

I’ve been playing around with the Google Maps APIs recently and imagine my disappointment when I found out that Google does not allow directions calculated through the APIs to be dragged around.

Not put off by this I decided to try and replicate the directions-dragging myself. How hard can it be?
As it turns out. Very, at least if you want to make it look as smooth as Google’s own solution.

When generating directions Google Maps adds a GPolyline element overlay to your map. You can set the returned line to be editable but this makes an awful lot of vertices appear on it, which makes reading your directions quite hard. Even so, once you dragged one of this vertices around you are not editing the route but just changing the shape of the line.

Mine is not a complete solution and I’m interested in feedback and ideas on how to improve it.

First off calculate your directions:

map = new google.maps.Map2(document.getElementById(‘map_canvas’));
var wayPoints = [];
wayPoints.push(startPoint.getLatLng());
wayPoints.push(endPoint.getLatLng());

var myDir = new google.maps.Directions(map)
myDir.loadFromWaypoints(wayPoints, { travelMode: G_TRAVEL_MODE_DRIVING });

This will calculate your driving directions and plot a GPolyline on your map. The line is easily accessible in the GDirections object once the directions are calculated. To intercept this I have decided to use the addoverlay event on the GMap object. This event is triggered every time something is plotted over the map (says on the tin).

google.maps.Event.addListener(myDir, "addoverlay", function() {
var dirLine = myDir.getPolyline(); // Get the polyline from the directions object
});

At this point we can ask the APIs to make the GPolyline editable. This will make the vertices appear on the line and make then draggable. As I said before this only changes the shape of the line and doesn’t actually affect your directions object. Luckily the GPolyline comes with a nifty event called lineupdated.
This is triggered once the user has finished dragging a vertex. By intercepting this we can look through the vertices and know what’s been changed on the line and where the vertex has been moved to.
In order to do this we must also know the previous position of the vertices (latitude and longitude) to be able to compare the old and the new “edited” line.
Another challenge is the fact that the GDirections object can accept only so many waypoints (25 if I’m not wrong). Which means we’ll have to add only the vertex that has changed to the directions and not all of them.

// In the addoverlay event also save the original vertices of the line
var origLine = [];
for (var i = 0; i < dirLine.getVertexCount(); i++) {
origLine.push(dirLine.getVertex(i));
}
// DONE saving vertices

// Now intercept the lineupdated event and add the new waypoints
google.maps.Event.addListener(dirLine, "lineupdated", function() {
routePoints = [];
for (var i = 0; i < dirLine.getVertexCount(); i++) {
var savedPoint = origLine[i];
if (!savedPoint || (savedPoint.lat() != dirLine.getVertex(i).lat() && savedPoint.lng() != dirLine.getVertex(i).lng())) {
routePoints.push(dirLine.getVertex(i));
}
}

// Now we remove the previous directions and recalculate the route
map.removeOverlay(dirLine)
calcRoute();
});

This works quite well but does not look as smooth as Google’s solution.
The problem is that while you are dragging a vertex only that bit of the GPolyline moves and the rest stays in its original position. which makes the shape of your directions quite awkward while you are dragging. Unforunately the GPolyline does not come with a “startdragging” event, otherwise we could just recalculate the route every few seconds while the vertex is being dragged.

This is not the most elegant of solutions but it does the job.

Tagged with:
Nov 21

While skimming through my RSS feed I stumbled upon an interesting article on Ajaxian about server side JavaScript programming.

I really, really enjoy writing JavaScript code so I decided to read through the article and take a look at the node.js library linked there.

node.js logo

Node is a framework to build server-side event-driven JavaScript applications. Developed in C++ on top of Google’s V8 JavaScript engine and accompanied by a set of JavaScript libraries Node seems to make building distributed (over a network), fast applications a piece of cake even for inexperienced developers.
Event-driven here really is the keyword because it represent a big change in the way applications are built (and architected in your brain).

Node is similar in design to and influenced by systems like Ruby’s Event Machine or Python’s Twisted. Node takes the event model a bit further—it presents the event loop as a language construct instead of as a library. In other systems there is always a blocking call to start the event-loop. Typically one defines behavior through callbacks at the beginning of a script and at the end starts a server through a blocking call like

EventMachine::run()

. In Node there is no such start-the-event-loop call. Node simply enters the event loop after executing the input script.

The example below (taken from Node’s website) will make everything clear… hopefully.

var sys = require(’sys’),
     http = require(‘http’);

http.createServer(function (req, res) {
  setTimeout(function () {
    res.sendHeader(200, {‘Content-Type’: ‘text/plain’});
    res.sendBody(‘Hello World’);
    res.finish();
  }, 2000);
}).listen(8000);
sys.puts(‘Server running at http://127.0.0.1:8000/’);

Can you see the beauty?!

I have only one worry. This is an open-source effort. The community behind it on Google groups is just 181 members strong (so far). What if node.js suddenly stops being the cool thing and the community disappears.

As much as I love writing JavaScript and I can really see the value in what they are building I’ll still wait until there are 100 Google Groups for node.js and a trillion members in each before using it in anything close to a production system.

Having said that I’m going back to writing silly node.js apps now. Well done to all the developers involved in the project and keep it up!

Tagged with:
Nov 11

I have just stumbled on an article on Slashdot about Google Go. A programming language which was initially developed internally and it’s now been open-sourced.

Over the past few months I have been working with Erlang on multi-process distributed systems. Concurrency in Go is based on the same model Erlang uses: Hoare’s Communicating Sequential Processes, or CSP.

Go’s concurrency primitives derive from a different part of the family tree whose main contribution is the powerful notion of channels as first class objects.

The thing I appreciate the most of Erlang is how easy it is to distribute – even over a network – and monitor processes. After skimming through Go’s documentation I couldn’t help but notice the lack of integrated network-distribution of processes or goroutines, as they are called.

This for me means that while Go, exactly like Erlang and Occam, simplifies the approach to multi-threaded programming (at least from a developer’s point of view), it doesn’t go all the way and leaves developers to deal with distribution of processes over a network on their own.

This is a perfectly acceptable design choice in the name of flexibility, however it creates a whole new bunch of use cases for the developers to deal with, such as sending channels/channels-data over the network).

What I don’t like of Erlang is its handling of strings, which makes it unsuitable for a number of application that could benefit greatly from its multi-processing capabilities. Very few people would recommend Erlang as a high performance string manipulation language. To quote Sendmail’s case study in implementing their Sendmail load balancing “Client Daemon” in Erlang:

…But Erlang’s treatment of strings as lists of bytes is as elegant as it is impractical. The factor-of-eight storage expansion of text, as well as the copying that occurs during message-passing, cripples Erlang for all but the most performance-insensitive text-processing applications.

Go totally wins on this.

If you now asked me to pick one to use. I’d still go for Erlang.
Functional languages and CSP are changing the way big companies approach the development of business critical applications. In the last year alone I have seen the number of positions advertised for Erlang developers in the financial sector multiply.
Go, if it continues on this path definitely has a chance of making it there. Open-sourcing the language is the right decision to give it the exposure to real-life scenarios that tend to accelerate the growth and adoption rate.

Tagged with:
Oct 31

This week I wrote a post comparing O3D and WebGL.

Today I have finally spent some time playing with O3D and managed to implement some very simple applications.

Now that I have a clearer understanding of what O3D can and can’t do I have given some thought to the possibility of writing videogames in JavaScript. As I mentioned in my previous post I can’t see myself playing something like Fallout in a browser window. Nonetheless I can imagine simple multiplayer games, something like Monopoly or Risk, working this way.

I have developed quite a few JS applications that allowed users connected at the same time to interact with each other. It’s very simple, constant AJAX posts and gets with a server keeping the state of the interaction. Imagine something like GTalk integrated inside GMail.

This is all well and good when the interaction is limited to a few chat messages or coordinates of the mouse pointer on the screen, but multiplayer videogames have to shift a massive amount of data every second. When you play Gran Turismo online the position, speed and state of each player’s car must e synched across all the participants as often as possible. Add chat/voice data to that and you’ll soon realise that 30 players for one game calling your server at the same time to get and post data is just not manageable. Furthermore to ensure the timely delivery of the data to each client you are much better off pushing the data to the client rather than relying on it to call your server.

What O3D should add to its APIs is a DirectPlay alternative. Multiplayer support built straight into O3D. This way your JavaScript game will be able to establish peer-to-peer communication between all the clients without having to stress your servers. Simple socket communication giving the developers the ability to push data between all the peers connected.
Network support by being built inside the O3D plugin could also deal with all the annoying connectivity issues such as “punching” through NATs.

Without properly implemented network play I don’t think we’ll ever see 3D games flourish in your browser window.

Tagged with:
Oct 29

You may have read recently that Khronos is implementing something called WebGL. The objective of the project is to expose all of OpenGL ES calls to javascript. Thus allowing hardware accellerated 3d graphics within a browser.
Google has also been working on an alternative, called O3D.

Let’s first talk about the technical differencies between the two projects.

O3D and WebGL while both trying to bring accellerated 3D graphics to the web have taken two fairly different courses. As I mentioned in the introduction to this post WebGL’s plan is just to expose to JavaScript OpenGL ES 2.0 APIs. Whereas Google’s solution is based on a browser plugin.

If we think about this we’ll soon realise that WebGL depends entirely on JavaScript. JavaScript, as of today, is a fairly slow language. This point was made in a discussion thread on the O3D project website.

WebGL, being 100% dependent on JavaScript to do an application’s scene graph, is going to have serious problems drawing more than a few pieces of geometry at 60hz except in very special cases or on very fast machines. This means WebGL requires JavaScript to:

*) do all parent-child matrix calculations for a transform graph.

*) all culling calculations (bounding box to frustum or other)

*) all sorting calculations for dealing with transparent objects.

*) all animation calculations.

As an example the kitty demo in O3D is doing linear interpolations on 2710 floats to animate 170 transforms. The point is not that the artist that created the kitty should probably not have used 170 bones. ;-) Rather the point is it seems unlikely that JavaScript
will be able to do that anytime soon and if it can then just add more than one kitty to pass its limits.

Also we have to keep in mind that not all hardware supports OpenGL ES.

O3D, By virtue of being a browser plugin written in C++, so an additional (hopefully fast) abstraction layer on top of the GPU, allowed Google to define a new set of APIs to expose to JavaScript and keep us (the JavaScript developers) away from the hardware. O3D will take care of the interaction with either DirectX or OpenGL.

Furthermore Google has open-sourced O3D through its Google Code website. Which means we can all have a look at their code and participate in the project. This resulted in a lot of documentation being available. For a full overview of how O3D works check out the technical overview on the O3D project page.

Do you think that this is the making of a new “Standards war”? Both Google and Khronos are adamant that they are not competing. However I believe that ultimately only one project will come out as a standard. As the complexity of 3D web applications increases it is not feasible to write code for both “APIs”. The only question for me at this point is who will come out on top.

To answer this I would look at the audience of the two projects. OpenGL has been out in the wild for a long while and many developers of videogames, or general graphic application, are already familiar with the APIs and the way it works, therefore it would probably make sense for them to embrace WebGL.
Nonetheless O3D still stands a chance. For a very simple reason. It’s the web we’re talking about.

Frankly I can’t see myself playing a big videogame like fallout in a browser window anytime soon. These APIs will be used to enrich web application. Some examples are already coming out using O3D. Have a look at this Home Designer. Can’t you already see IKEA using it.
My point here is that we’re not likely to see game developers switch to the web. We’re much more likely to see web developers start working on games or application involving 3d graphics, and this is where Google wins.

O3D extends application JavaScript code with an API for 3D graphics. It uses standard JavaScript event processing and callback methods.

As a web developer I can keep writing JavaScript code as I’m used to without having to change the way I think to how a game developer does.

What do you think?

Tagged with:
Oct 28

Ever since Schmidt resigned from Apple’s board we all knew that a feud between the two companies was about to start.

Google had just launched Android, a Mobile OS. I’m sure we are all too aware of this.
Android wasn’t, and still isn’t a serious competitor for Apple’s iPhone. Google’s OS still has a long way to go to reach the “slickness” of the iPhone OS. Furthermore Google doesn’t have control over the hardware running its OS. Which means that the brilliancy of the OS can be completely overshadowed by the absurdity of the hardware. Honestly, some of the Android phones look like they have been designed by some boffin called Jenkins who was given complete freedom by their boss, Who should have instead said “No Jenkins you imbecile that’s not a phone. It’s crap. Do it again.”

I’m getting side-tracked. Let’s get back to the point.

Today Google announced Google Map Navigation for Android; and somehow I doubt it will make it to the iPhone. My guess is that Google is repaying Apple in kind for the whole Google Voice debacle. This is a serious blow and Apple will have some work to do to catch up with this.

More importantly Google Maps Navigation runs entirely off the net.
I have an iPhone with the Navigon app. It’s great but on my slim 8GB iPhone 25% of the storage is used for Navigon maps. With mobile internet connectivity becoming ever more ubiquitous this is definitely the way to go.

All I can hope for is that the rumor that came out a while ago about Google developing its own mobile phone is true. Then I might seriously consider giving up my iPhone.

UPDATE: AppleInsider reports that Google is in fact planning to port Google Maps Navigation to iPhone. If Apple approves the application, that is. Just PR or are they actually working on it?

“Apple is a close partner,” a Google spokesperson told AppleInsider Wednesday. “Millions of users experience Google Maps on the iPhone. We will continue to work with Apple to bring innovation, including Latitude and Navigation, to users but you’ll have to speak to Apple about availability.”

Tagged with:
Nov 27

After much anticipation and hype the Gdrive seems to be on its way, or so the WSJ reports.

A Google spokeswoman declined to comment on any specific online storage plans beyond what it already offers as part of its email and other services. But she said in a statement that “storage is an important component of making Web [applications] fit easily into consumers’ and business users’ lives.”

Most companies, from small businesses to big giants are moving their environments online to make documentation/presentations or whatever else may be needed available to their employees, wherever they may be whenever they want.

As I said in a previous post Google is pushing its online productivity suite and a shared online storage could definitely give an additional boost to the entire system.
The online storage is one of the few reasons why I use .Mac, the second rationale behind the choice is that the interface is just brilliant, the iDisk is mounted as a file system and directly accessible from my Finder.

In my opinion if Google really wants to make the Gdisk a must have for small/big businesses a client software to access the data is vital – not because it works better, but because it is a step final users have to go through to get used to online storage solutions. Most people don’t, and won’t for a while, use Writely or Google’s new PowerPoint-ish software – they’ll keep creating documents in their local environment and the sensation of accessing a local drive to save their work will make them feel somewhat more secure.

For its office components to attract big businesses Google still has do a great deal of work on the corporate accounts handling side – being able to organize accounts in groups and set different access permissions on a Gdisk’s folders would be a great start.
Another useful additional feature, which as I understand is due sometime soon, is offline availability of the applications. An internet connection is not always available and an entire company can’t just stop working because IT people in the basement are messing around with routers.

Having said that it’s not only functionality-related issues Google has to address but also privacy and security questions. If they want more of our data to be stored on their servers, and with Gdisk it wouldn’t only be images and documents but all sort of data we may not want other people to see, we expect Google to have some pretty satisfactory answers ready – Especially when we’re talking about reserved and potentially vital information its business customers save in the cloud.

Tagged with:
Nov 20

There’s been a couple of rumors floating around in the last two days regarding everyone’s favorite internet giant, Google.

First came the news about Ebay selling Skype after losing a little bit more than 1 billion dollars over the value of the initial acquisition. Google is of course named among the potential bidders.
Now we hear that Google is getting ready to bid for some of the coveted 700-megahertz spectrum in the auction due to begin on Jan 24th.

Google phone “From the company’s perspective, the overriding factor is how to foster more openness in networks. That is certainly the driving factor in our thinking about bidding on the spectrum.”
The 700-MHz band airwaves, which are being returned by broadcasters as they move from analog to digital signals early in 2009, can go long distances and penetrate thick walls. The auction is seen as a last chance for a new wireless player.
Google is considering funding a bid not only from its growing cash pile but by working with Wall Street. Outside financing would reduce its need for partners, one source said.
Google has said it would be prepared to bid at least $4.6 billion for the biggest chunk of spectrum if regulators agreed to policies to promote open use of such networks.

Now I don’t know about you but I definitely think that this is a BIG deal. Google seems to be gearing up to do something more than just release an open-source OS for mobile phones.
The internet giant could, with these 3 items in its shopping cart, seriously corner the mobile internet market.

Another thing comes to mind. By integrating Skype on all its android-powered mobiles and providing said mobiles with free/cheap wireless connectivity Google could easily score a checkmate against the major carriers.

It’s all good and well but such a move certainly isn’t cheap. Google would have to bring in some partners to finance the entire operation. If instead of picking a partner it will “work” with Wall-Street as the article quoted above suggests it will still have to give away some of the control they might have by being the only player.

If we do some math we have something between 1.2 and 1.5 billion $ to buy Skype off Ebay (just a guess off the top of my head). Anything between 4.5 and 5 billion $ for the band airwaves. To these costs we have to add another hefty sum which Google will have to cough up to maintain Android free whilst building and evolving it.

I think we are looking at a total of around 7 to 8 billion. Let me say it again, this is a BIIIIG deal, Google is betting big here and if something goes wrong – which is very likely as I don’t think giants like AT&T or Verizon will concede without a fight – They’ll be in big trouble. Google’s market cap at the moment is of 195.79 billion $, however with the current volatility of the markets I wouldn’t put too much trust in that number – The statistic we have to keep in mind is that according to its sec filings Google has something around 13 billion $ in cash available, a big sum, but looking at the figures I mentioned above the sum looks a bit stretched.

Tagged with:
Nov 18

SiliconValley.com is reporting that AT&T is currently considering joining Google and its mobile-phone software alliance.

The phone company is “analyzing the situation” and may use Google’s software for phones, Ralph de la Vega, chief executive officer of the wireless unit, said in an interview Friday

It is a peculiar move for a telecoms giant who bent over backwards to accommodate Apple and its iPhone. Could it be that AT&T already feels its time to start distancing itself from the super-hyped product and let it join the ranks of the other unimportant devices?

Given the wide variety of services and the stellar number of customers AT&T has this is may very well be considered a natural move in the attempt of pushing future products. Nonetheless I’m sure the move will give some PR-related grief to AT&T, especially considering the VIP-ish marketing campaign they put up for Apple’s gizmo.

Tagged with:
Nov 17

Google takes yet another step in its battle against Microsoft for domination of the corporate environment.

The software giant has recently released a set of APIs which will make migration from a Microsoft/any-other-system-you-may-use to Gmail incredibly simple.

“We’ve provided developer documentation and sample code that allows developers to build extremely sophisticated mail migration tools, some of which can be run by administrators to migrate centralized mail and some of which can be run by end-users to migrate mail from the desktop,” — Gabe Cohen, Google Apps product manager.

I couldn’t find any data about the usage of Google documents around. I expect the uptake of the application to be extremely high among non-corporate users. However, It seems that it will take a bit longer for small businesses and startups to get used to the service and start using it. Especially considering that most users have been educated in a Microsoft-ruled environment their entire professional life.

Google had previously released another set of tools to allow users and system administrators to migrate from most IMAP-based e-mail systems to Google Gmail.

Furthermore, as much as this set of APIs is a very interesting development, I hardly see a big corporation spending a considerable amount of dough and development time to migrate its entire system, similarly it’s going to be even harder for small business find the time and money to dedicate to this. Don’t take me to seriously now though. Companies like Capgemini, with 80,000 employees are in fact putting a first toe in the water and using Google Apps for some of its employees.

Nevertheless I’m sure all sort of open-source/free applications will sprout all over the internet to let disgruntled Outlook users switch to Gmail.

Tagged with:
preload preload preload