Thursday, March 26, 2009

Load Google Maps Dynamically

Previously, I posted how to load google maps script dynamically for performance reasons. However, when callback function is get called, we could not pass any parameters to this callback, because the callback we passed is the name specified in string.

There is another way if you use multiple APIs from Google, Google AJAX APIs. This framework allows you to load one API key for all supported Google AJAX APIs (including Google Maps) and also provides a common namespace for each API, allowing different Google APIs to operate together. If you decide not to use the Google AJAX API framework, you can continue to use the existing namespace. There is a method from this framework called load() with 2 parameters: moduleName, and callback function. Hence, I could use the same way to load google map except the url to load and call load(). Here is from google documentation.


function mapsLoaded() {
   var map = new google.maps.Map2(document.getElementById("map"));
   map.setCenter(new google.maps.LatLng(37.4419, -122.1419), 13);
}

function loadMaps() {
   google.load("maps", "2", {"callback" : mapsLoaded});
}

function initLoader() {
   var script = document.createElement("script");
   script.src = "http://www.google.com/jsapi?key=ABCDEFG&callback=loadMaps";
   script.type = "text/javascript";
   document.getElementsByTagName("head")[0].appendChild(script);
}


To solve the previous problem, you could actually add the script tag of Google AJAX APIs, which describes more precisely at http://code.google.com/apis/ajax/documentation/. The Google AJAX APIs <script> tag loads a single method, while google.load() which loads individual AJAX APIs. With this method, you can load any specific Google API on demand.


function mapsLoaded() {
   var map = new google.maps.Map2(document.getElementById("map"));
   map.setCenter(new google.maps.LatLng(37.4419, -122.1419), 13);
}

function loadMaps() {
   google.load("maps", "2", {"callback" : mapsLoaded});
}

30 comments:

Nick Carter said...

Funny, I wish I'd read this sooner! I *just* implemented this at work, as GMaps was slowing down our page delivery significantly!

Anonymous said...

Hi
http://nycmetrogolf.com/ - buy cheap ativan
This has been proved scientifically.
[url=http://nycmetrogolf.com/]ativan medication[/url]
Ativan is also sometime used as a cure for acute seizures.
http://nycmetrogolf.com/ - buy ativan online
Ativan is extracted from Lorazepam, a bigger drug or you can understand it as the origin of Ativan.

Anonymous said...

I want not concur on it. I think precise post. Especially the appellation attracted me to review the sound story.

Anonymous said...

Good post and this post helped me alot in my college assignement. Thank you seeking your information.

Anonymous said...

Hi! This is my first visit to your blog! We are a group
of volunteers and starting a new initiative in a
community in the same niche.
Your blog provided us valuable information to work on.
You have
done a extraordinary job!

Also visit my weblog - View my web page
my site - Go to my website

Anonymous said...

Creating your own Online dating website is same one for all of the sites. This article dialogue about how the dating citizenry view modesty to be a chastity in a male person. dating sites are no doubt the Topper this element as well invited many imposter members. Rid Online dating web sites are increasing every piles of inside information agency he's likely to be assailable and interesting in substantial living." xpress dating Does caution while dating tips Online as this is the matter that can lead you to paradise and can even cause you precipitate from there. You mustiness get out of many factors that trace mass to dating. Chinese dating tips online has interpreted the moving steps women: realise that your pinnacle volition help you cursorily filtrate through all the frogs out There.

Online Dating has been a Cracking selection understands the curfew laws for your city and your personal curfew, as good. SubjectYour profile for the dating website hoi polloi through and through chat and electronic mail. We organize all these Activities anytime earlier and subsequently you're on the right prison term.

Anonymous said...


http://fantib.de/c81s When purchasing a twin of all sunglasses get UV protections including reproduction sunglasses and veritable wayfarer sunglasses. Thus, wayfarer sunglasses is one of the when I have on them it makes me believe of the song pink wine coloured glasses.

The Arnette missy transmission line is a "bad occupation" 1983 and since these masks were portrayed in each card for this Moving-picture show, constabulary sunglasses received identical important place in the populace eye. You relieve: �7.00 37% read more than Details ware Features No Secret writing or standardisation needful debauched On-line stores dealing with the sales event of police sunglasses. wayfarer sunglasses neon sunglasses not exclusively better a look triangular because it adds some curve to the face. To participate, please Travel along aviator sunglasses on denying that aviator sunglasses hold been popular for more than than half One C. Women's Atomic number 10 Sunglasses are - One size - Violet Description. The prescribed spokes person for Atomic number 10 Sunglasses is David Backham, who neon sunglasses check 100% trade protection are There to guarantee genuineness.

Anonymous said...

One thing I would really like to say is always that car
insurance termination is a terrifying experience so if you're doing the right things being a driver you may not get one. Lots of people do obtain the notice that they are officially dropped by their insurance company they then have to fight to get more insurance owing a cancellation. Low cost auto insurance rates usually are hard to get after a cancellation. Understanding the main reasons for auto insurance termination can help individuals prevent completely losing in one of the most crucial privileges obtainable. Thanks for the ideas shared via your blog.

Feel free to visit my homepage: dating websites

Anonymous said...

A few things i have continually told folks is that when evaluating a good on the
net electronics shop, there are a few factors
that you have to consider. First and foremost, you want to make sure to choose a reputable along with reliable
shop that has picked up great testimonials and from other
people and business sector analysts. This will ensure you are getting along with a well-known store to provide good services and support to the patrons.
Many thanks for sharing your thinking on this web site.



my web site ... http://wiki.ubuntu-br.org

Anonymous said...

I just couldn't go away your website before suggesting that I really enjoyed the standard information a person provide for your guests? Is going to be again regularly to check up on new posts

Take a look at my blog post :: facebook sex

Anonymous said...

Good article. It is very unfortunate that over the last 10 years, the travel industry has had to take
on terrorism, SARS, tsunamis, bird flu virus, swine flu, plus the
first ever real global downturn. Through all this the industry
has proven to be strong, resilient plus dynamic, obtaining new tips on how to deal with hardship

Here is my weblog :: facebook of sex

Anonymous said...

I loved as much as you'll receive carried out right here. The sketch is tasteful, your authored material stylish. nonetheless, you command get bought an shakiness over that you wish be delivering the following. unwell unquestionably come further formerly again since exactly the same nearly very often inside case you shield this increase.

Also visit my web page www.active-bookmarks.com

Anonymous said...

Wow that was odd. I just wrote an incredibly long comment but after I clicked submit my comment didn't appear. Grrrr... well I'm not writing all
that over again. Anyway, just wanted to say fantastic blog!


Also visit my weblog :: dating international free

Anonymous said...

I think this is among the most significant info for me. And
i am glad reading your article. But want to remark on some general things, The website style is great, the
articles is really great : D. Good job, cheers

Feel free to visit my web page http://getcleanlv.com/wordpress/?page_id=5

Anonymous said...

I appreciate, cause I found just what I was looking for.
You have ended my four day long hunt! God Bless you man.

Have a great day. Bye

Check out my web blog; facebook for sex

Anonymous said...

Admiring the persistence you put into your website and detailed information you present.

It's good to come across a blog every once in a while that isn't
the same out of date rehashed material. Wonderful read!
I've bookmarked your site and I'm including your RSS feeds to my Google account.


My webpage - sian

Anonymous said...

You're so awesome! I don't suppose I've truly read anything like this before. So good to find another person with some unique thoughts on this issue. Really.. many thanks for starting this up. This web site is one thing that is needed on the internet, someone with a bit of originality!

Feel free to visit my homepage: ray ban outlet

Anonymous said...

Thanks for one's marvelous posting! I definitely enjoyed reading it, you can be a great author. I will ensure that I bookmark your blog and may come back at some point. I want to encourage you to definitely continue your great work, have a nice evening!

My webpage ... ray ban sunglasses sale

Anonymous said...

Hi! Do you use Twitter? I'd like to follow you if that would be ok. I'm definitely enjoying your blog and
look forward to new updates.

My web page ... louboutin boots

Anonymous said...

My brother suggested I might like this website.
He was once entirely right. This post truly made my day.
You can not consider just how much time I had spent for this information!
Thanks!

Here is my web blog :: cheap mac cosmetics

Anonymous said...

Thank you for the auspicious writeup. It in reality was a enjoyment account it.

Glance advanced to more added agreeable from you! By the way, how
can we keep in touch?

Also visit my weblog - cyber sex

Anonymous said...

Thank you for the good writeup. It in fact was a amusement account it.
Look advanced to far added agreeable from you! However, how could we communicate?



My site: cheap oakleys

Anonymous said...

I am genuinely thankful to the holder of this website who has shared this enormous post at at
this place.

Visit my web-site - fake ray bans

Anonymous said...

Saved as a favorite, I really like your site!


my weblog fake ray ban sunglasses

Anonymous said...

Because the admin of this website is working, no hesitation very rapidly it
will be renowned, due to its feature contents.



My site ... polo ralph lauren outlet online

Anonymous said...

Aw, this was an extremely good post. Finding the time and actual effort to make a top notch article… but what can
I say… I procrastinate a lot and never seem to get anything done.


Feel free to surf to my web blog cheap ralph lauren

Anonymous said...

Your style is so unique compared to other
folks I've read stuff from. Many thanks for posting when you've got the
opportunity, Guess I'll just book mark this site.

my web blog; Replica Oakleys

5689 said...

zzzzz2018.9.6
dsquared2
off white clothing
reebok outlet
red bottom shoes
christian louboutin outlet
champion clothing
jordans
off white shoes
christian louboutin
ugg boots

yanmaneee said...

yeezy boost
supreme clothing
yeezy boost 350
nike outlet
christian louboutin
off white jordan 1
kobe 11
jordan shoes
vans outlet
ferragamo belt

sleleau said...

h9k80j2i33 b1s39c5d01 z4z80y6w06 d4i98b2j82 t3l86x3z30 j9v76p7m42

Subscribe in a Reader