Can I put google map functions into a closure?

Posted by Joe on Stack Overflow See other posts from Stack Overflow or by Joe
Published on 2010-02-10T00:05:29Z Indexed on 2010/06/01 23:13 UTC
Read the original article Hit count: 149

Filed under:
|

I am trying to write some google map functionlity and playing around with javascript closures with an aim to try organise and structure my code better.

I have the following code:

var gmapFn ={
    init : function(){
        if (GBrowserIsCompatible()) {
            this.mapObj = new GMap2($("#map_canvas"));
            this.mapObj.setCenter(new google.maps.LatLng(51.512880,-0.134334),16);
        }
    }
}

Then I call it later in a jquery doc ready:

$(document).ready(function() {
    gmapFn.init();
})

I have set up the google map keys and but I get an error on the main.js :

uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://maps.gstatic.com/intl/en_ALL/mapfiles/193c/maps2.api/main.js :: ig :: line 170" data: no] QO()

THe error seems to be thrown at the GBrowserIsCompatible() test which I beieve is down to me using this closure, is there a way to keep it in an closure and get init() working?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about google-maps