Loading Google Maps in asynchronous mode with JQuery

{1 Comment}

When using JQuery and Google Maps javascript API together, is possible to have slowness problems waiting for the document ready event.

The solution maybe to load the Google Maps API in asynchronous mode, so that  all the page building stuff based on the document ready event doesn’t have to wait for the Google Maps loading.

Here (jquery.gmapstools) is a simple JQuery plugin that uses this technique and implements two commong tasks that everyone may meet:

1) showing a map:

$.gmapstools.init();
$("#my_map_canvas").gmap({lat:37.4221913, lng:-122.08458530000001, draw_marker:true, zoom_level:13});

2) geocoding an address:

/**
result will be an object of type GeocoderResults or an error message
*/
function geopos_callback(result){
	if(result.formatted_address){
		alert(result.formatted_address+ " "+result.geometry.location.toString());
	}else{
		alert(result);
	}
}

$.gmapstools.init();
$.gmapstools.codeAddress("1600 Amphitheatre Parkway Mountain View, CA 94043", geopos_callback);

 

1 Comment…

 Share your views
  1. Hurrah! After all I got a weblog Loading Google Maps in asynchronous mode with JQuery from where I can in fact get useful information regarding my study and knowledge.

Leave a Comment

Your email address will not be published.