To use the Google’s Visualization GEO API with CodeIgniter, instructions below on how to do it.
Create a map based on that data.
Now the example given is great, however it doesn’t jive well when you want to add in a friendly library like jQuery. So here is how I fixed it:
The Controller – maps.com
public function index() {
$data = $this->Maps_m->get_map_country();
// Pass the data t the template, using the variable map
$this->template->map = $data;
// Load the views using the templates
$this->template->build('maps');
}
The Data Model
public function get_map_country() {
return $this-db->
select("geo_country.country, COUNT( * ) as mediahits", false)
join('news_item_country', 'news_item_country.id=news_items.country')
join('country', 'news_item_country.country=country.id')
join('geo_country', 'geo_country.id=country.geo_country')
where('news_items.deleted', '0')
group_by('geo_country.country')
get('news_items')
result_array();
}
The View
Then we just needed load the data from the database and create the map.
< script src="https://www.google.com/jsapi" type="text/javascript">
< script type="text/javascript">
google.load('visualization', '1', {'packages': ['geochart']});
google.setOnLoadCallback(drawRegionsMap);
function drawRegionsMap() {
var data = google.visualization.arrayToDataTable([
['Country', 'Media Hits'],
[';'],
;],
;
]);
var options = {};
var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
chart.draw(data, options);
};
No comments:
Post a Comment