Google Maps API Library for CodeIgniter Framework
UPDATE: I have now released a new version of this library that uses Version 3 of the Google Maps API.
I am pleased to announce that the first release of my Google Maps API library for the PHP framework CodeIgniter is now ready and available for download.
Seeing as every other website I create seems to use the Google Maps API in some shape or form I finally decided to take it upon myself to create a library in order to reduce the work required to get this setup.
To get a copy or to read the documentation simply follow the links below:
If you have any questions, spot a bug or would like to leave feedback please leave a comment below or drop me a line.
I have lots of ideas on how to enhance this library and will continue to announce updates as development continues.
Enjoy!!
thank you very much
Nice work! Keep it up :)
thank you !!!
@Chanthoeun – Thanks for the kind words. Glad you like it. It looks like you’re using the old version of the library. Firstly I suggest you get the new version which uses version 3 of the Google Maps API.
I’m not sure if I fully understand what you’re trying to achieve but will assume you are trying to add a marker to the map where the click occurs? With the latest library you can do something like so when initializing the map:
$config[‘center’] = ‘37.4419, -122.1419’;
$config[‘onclick’] = ‘createMarker({position: event.latLng, map:map});’;
$this->googlemaps->initialize($config);
Let me know if I’ve got the wrong end of the stick here :) Cheers
Hello Steve, You did a great work.
I have a question to ask you. Do you have any way to get Lat and Long when we click to add marker on map?
Thanks
Thanks for share Steve ;D
I have just released a version of this library that uses Version 3 of the Google Maps API. Click here to read more
Thanks for the amazing library. So easy to use, and incredibly helpful. Great work!
@Jason
You never know :-P I’ve been thinking about adding a lot more functionality recently (directions etc). I’m planning on releasing another update within the next two weeks so watch this space :)
One more question for you. :)
Any plans on supporting API V3?
@Jason
Let’s presume that the function you have provided is in a model called ‘businesses_model’. You would change this function to be as follows:
function addressForMap($id) {
$row = array();
$this->db->select(‘b.id, b.busaddress, b.buscity, b.buszip’);
$this->db->from(‘business as b’);
$this->db->where(‘b.id, $id);
$query = $this->db->get();
if ($query->num_rows() > 0) {
$row = $query->row_array();
}
return $row;
}
In your controller you would then do as follows:
// Load our model (as above) and the downloaded library
$this->load->model(‘businesses_model’, ”, TRUE);
$this->load->library(‘googlemaps’);
// Get the address of the business, where ‘5’ is the ID of the business in question
$address = $this->businesses_model->addressForMap(5);
// Initialize and create our map, passing in any configuration values we require
$config[‘apikey’] = ‘YOUR_API_KEY’;
$config[‘center_address’] = join(“, “, $address); // Center the map on the address
$this->googlemaps->initialize($config);
$data[‘map’] = $this->googlemaps->create_map();
// Set and add the marker
$marker = array();
$marker[‘address’] = join(“, “, $address);
this->googlemaps->add_marker($marker);
// Load our view, passing the map data that has just been created
$this->load->view(‘your_view_name’, $data);
Then in your view in your <head></head> tags add:
< ?php echo $map['javascript']; ?>
And where you want the map to appear add:
< ?php echo $map['mapdiv']; ?>
Please note I haven’t tested the above but I hope that it gives an understanding on how to use the library in the context required.
Let me know if you have any questions about anything above :)
I’ve got a question for you. My addresses are stored in a db. I’m pulling up a page where the information is all dynamic. For example: mysite.com/site/business/5 (where 5 is the id of the business).
Let’s say I do a query like this:
function addressForMap($id) {
$this->db->select(‘b.id, b.busaddress, b.buscity, b.buszip’);
$this->db->from(‘business as b’);
$this->db->where(‘b.id, $id);
}
How can I output the info to the google maps api correctly so that it display’s the map appropriately?
the article is pretty informative. it actually provide me what i’ve searching for. Thank you for Sharing
@vincenzo
An excellent idea and something I was actually already part way through.
I can confirm that the ability to center the map and position markers based on an address has now been completed and is part of the download. Simply click the download link from within the post. Also note the ‘google_host’ config value if using the map within a specific country. Cheers
is possible to use this, with geoder instead of lat and long for marker? thanks
Thanks for that steve, great work!