Skip to content

Instantly share code, notes, and snippets.

@yaph
Created January 21, 2012 16:19
Show Gist options
  • Save yaph/1653194 to your computer and use it in GitHub Desktop.
Save yaph/1653194 to your computer and use it in GitHub Desktop.
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'});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment