Google Maps API Library for CodeIgniter Framework

May 1st, 2010 - Posted by Steve Marks to Javascript / jQuery, PHP, Web Development.

CodeIgniter Library - Google Maps API

UPDATE: I have now released a new version of this library that uses Version 3 of the Google Maps API.

Click Here to Read More

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:


View Documentation PDF (61kb)

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.


This entry was posted on Saturday, May 1st, 2010 at 1:09 am by +Steve Marks and is filed under Javascript / jQuery, PHP, Web Development. You can follow any responses to this entry through the RSS 2.0 feed.

Fear not, we won't publish this

Comments (16)
  1. paraz says:

    thank you very much

  2. ajith says:

    Nice work! Keep it up :)

  3. azerty says:

    thank you !!!

  4. @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});’;

    Let me know if I’ve got the wrong end of the stick here :) Cheers

  5. Chanthoeun says:

    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?


  6. alberto says:

    Thanks for share Steve ;D

  7. I have just released a version of this library that uses Version 3 of the Google Maps API. Click here to read more

  8. Peter says:

    Thanks for the amazing library. So easy to use, and incredibly helpful. Great work!

  9. @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 :)

  10. Jason says:

    One more question for you. :)

    Any plans on supporting API V3?

  11. @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.busaddress, b.buscity, b.buszip’);
            $this->db->from(‘business as b’);
            $this->db->where(‘, $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);

        // 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
        $data[‘map’] = $this->googlemaps->create_map();

        // Set and add the marker
        $marker = array();
        $marker[‘address’] = join(“, “, $address);

        // 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 :)

  12. Jason says:

    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: (where 5 is the id of the business).

    Let’s say I do a query like this:

    function addressForMap($id) {
    $this->db->select(‘, b.busaddress, b.buscity, b.buszip’);
    $this->db->from(‘business as b’);
    $this->db->where(‘, $id);

    How can I output the info to the google maps api correctly so that it display’s the map appropriately?

  13. the article is pretty informative. it actually provide me what i’ve searching for. Thank you for Sharing

  14. Steve Marks says:

    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

  15. vincenzo says:

    is possible to use this, with geoder instead of lat and long for marker? thanks

  16. Thanks for that steve, great work!