Google Maps API’s Error Handling

Requirements to try out things described below:

Super large numbers as LatLng’s

Open this page from Google’s example. In firebug’s console, execute the following code:

map.setCenter(new GLatLng(1e100, 1e100));

Setting super large numbers as latitude and longitude like this always makes my Firefox 2.0.0.11 in Windows XP hang.

I don’t know why Google didn’t restrict the range of the numbers, and what computation it did to consume so much CPU time. It should ignore such numbers after a simple judgment.

Strings as zoom parameters

In the same page, execute this piece of code:

var zoom = '16';
map.setZoom(zoom);

As you see, nothing happens. Google must be ignoring the parameter when expression typeof(zoom) == ‘number’ is false. In my situation, I got the value of variable zoom from the url, and didn’t noticed it was the type mismatch which prevented the code to work, since I’m used to JavaScript’s dynamic type conversion feature:

a = 2 * '3'; // a = 6

It will be converted to number when needed. Of course, it’s good to perform strict type checking. But it’ll be better if the API threw an exception instead of being silent.