Google Maps API Documentation
Google Maps API Documentation
Google Maps API Documentation
CodeIgniter Library
Version: 1.1 Author: BIOSTALL (Steve Marks) Website: http://biostall.com Email: info@biostall.com
Introduction
This CodeIgniter library provides an easy way to display simple maps within an application/website using the Google Maps V2 API. It allows maps to be shown, including customisable markers, with just a few lines of code.
Installation
In order to use the library you will need to download the Googlemaps.php file and place it in the libraries directory of your application folder. Following the demonstrations and documentation below you will then be able to begin creating maps right away.
The Basics
Once the installation instructions above are complete there are just two things we need to do to in order to create a map. The first is to amend our controller in order to initialize and customise our output, and the second is to include two lines of code in our view where we want the map to be displayed: The Controller The example below shows how to create a simple map with all the default controls and no markers:
// Load the library $this->load->library('googlemaps'); // This is our Google API key. You will need to change this for your own website $config['apikey'] = 'ABQIBAAADiypSsSGMm4zOSm7T0Nf1BT2yXp_ZAY8_ufC3CFXhHIE1NvwkxTegq9k46u7yla9Jc-SjozzP0J8ig'; // Initialize our map, passing in any configuration values we have set $this->googlemaps->initialize($config); // Create the map. This will return the Javascript to be included in our pages <head> section and the HTML code to be // placed where we want the map to appear. $data['map'] = $this->googlemaps->create_map(); // Load our view, passing the map data that has just been created $this->load->view('my_view', $data);
The View There are two things we need to add to our view. The first is the Javascript which should be placed in the <head> section of your website as follows:
<head> <?php echo $map['javascript']; ?> </head>
The next thing is the actual map. This should be placed where you want the map to appear as follows:
<?php echo $map['mapdiv']; ?>
map_height
string
450px
center_lat_long
string
37.4419, -122.1419
center_address
string
One or more controls to GLargeMapControl3D, display on the map GLargeMapControl, GSmallMapControl, GSmallZoomControl3D, GSmallZoomControl, GScaleControl, GMapTypeControl, GHierarchicalMapTypeControl, GOverviewMapControl, GNavLabelControl FALSE TRUE or FALSE If no controls are not set, turning this to FALSE will hide the default controls A URL to the image to be used for all marker icons if markers are placed on the map. maps.google.com If using the map to display markers in a certain country, you will get better results if you change this to the country in question. For example, if ony displaying markers in Germany, change this value to maps.google.de TRUE or FALSE Turn to TRUE if the device on which the map is being displayed contains tracking functionality.
hide_controls
boolean
icon_image
string
google_host
string
sensor
boolean
FALSE
Adding Markers
The library also allows you to add multiple markers to the map at specified positions. To add a single marker we can add the following code before the create_map() function is called:
// Set the marker parameters as an empty array. Especially important if we are using multiple markers $marker = array(); // Specify the address for where the marker should appear. Alternatively we can use the lat_long value $marker['address'] = 'Crescent Park, Palo Alto'; // Once all the marker parameters have been specified lets add the marker to our map this->googlemaps->add_marker($marker);
To create multiple markers simply duplicate the above code the required amount of times. Like the map itself, we can also specify a number of parameters for individual markers to change how and where they appear. These parameters are as follows:
Name lat_long address Type string String Default Possible Values Description The latitude and longitude at which to show the marker As an alternative to positioning markers based on a latitude and longitude, you can use an address instead. text or html If you want to show an infowindow/bubble you can specify whether to use a text or HTML version. The HTML version allows HTML tags, styling and images. If infowindow_type is set, this is the text/HTML to show in the infowindow/bubble. FALSE TRUE or FALSE Whether to open this markers infowindow/bubble by default when the page loads. If multiple markers have this set as TRUE, only the first infowindow will open by default. A URL to the image to be used for this marker. If icon_image is set on the map, the marker icon_image will take priority.
infowindow_type
string
infowindow_content
string
infowindow_open
Boolean
icon_image
string
To leave feedback, ask questions or report bugs please contact me at info@biostall.com or leave a comment at http://biostall.com.