Skip to content

Google Maps API V3 Library

Derek Jones edited this page Jul 5, 2012 · 4 revisions

Category:Contributions | Category:Contributions::Libraries | Category:Contributions::Libraries::Google Maps

Once again, the php code beghind the API isn't actually mine, kudos for that goes to the incredibly talent guys at the php-google-map-api project which can be found here? http://code.google.com/p/php-google-map-api/

I have modified their code slightly and put it in a nice, pretty CodeIgniter wrapper.

The following table is required for the caching functionality of the library.

CREATE TABLE geocode_cache (
id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
lng double NOT NULL,
lat double NOT NULL,
query varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL
);

Then, all you need to do is copy the GMap.php and JSMin.php files to your code igniter library directory.

A quick tutorial. To generate a very basic map, with a marker generated from an address?

$this->load->library('GMap');

$this->gmap->GoogleMapAPI();

// valid types are hybrid, satellite, terrain, map
$this->gmap->setMapType('hybrid');

// you can also use addMarkerByCoords($long,$lat)
// both marker methods also support $html, $tooltip, $icon_file and
$icon_shadow_filename
$this->gmap->addMarkerByAddress("42 Beanland Gardens, Wibsey, Bradford,UK","Marker Title", "Marker Description");

$data['headerjs'] = $this->gmap->getHeaderJS();
$data['headermap'] = $this->gmap->getMapJS();
$data['onload'] = $this->gmap->printOnLoad();
$data['map'] = $this->gmap->printMap();
$data['sidebar'] = $this->gmap->printSidebar();

$this->load->view('template',$data);

Your template file should look similar to the following?

<html>
<head>
<title>Map Test</title>
<?php echo $headerjs; ?>
<?php echo $headermap; ?>
</head>
<body>
<?php echo $onload; ?>
<?php echo $map; ?>
<?php echo $sidebar; ?>
</body>
</html>

This library supports almost every feature present in the new google maps api version 3 and as such is incredibly full featured.

The library can be downloaded from http://www.in-the-attic.co.uk/2010/08/02/codeigniter-google-maps-library-using-google-maps-api-version-3/ and some comprehensive tutorials can be seen http://www.in-the-attic.co.uk/2010/08/03/google-map-library-for-codeigniter-example-usage-update/.

Thank you for taking the time to use my libraries. As always, please do not hesitate to notify me of any bugs you might find.

The original thread for this can be found here, http://codeigniter.com/forums/viewthread/164367/.

Clone this wiki locally