FDiri
1/21/2012 - 4:19 PM

Load JSON data and then dynamically load Google Maps API V3 to display a map using the data

Load JSON data and then dynamically load Google Maps API V3 to display a map using the data

$.getJSON('http://example.com/getjson, function(dataJSON) {
  $.getScript('http://www.google.com/jsapi?key=API_KEY', function(data, textStatus){
    function mapLoaded() {
      var myOptions = {
        center: new google.maps.LatLng(dataJSON.lat, dataJSON.long),
        zoom: 8,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      };
      var map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
    }
    google.load('maps', '3', {'callback' : mapLoaded, 'other_params':'sensor=false'});
  });
});