Codeigniter Geolocation Library

No votes yet.
Please wait...

Most of us know that there are various useful external libraries present for Codeigniter. In this post we will explore how to implement CI Google Maps Library.

Many of you may have gone through a situation where you want to have google markers respective to the locations.So why do it in conventional way when you have got license to go for the Google Maps library in CI.

Let’s Explore the Google map Library.

  • First of all, download the google maps library file and navigate to libraries folder inside application folder and paste the file.
  • Now, Load the google map library file in either constructor or the function which you are using inside the controller.
  • Now its time for some coding. Fetch all the locations dynamically from your database.Now once you have an array containing multiple location’s paste the following code in your controller

My sample controller

public function index()
{

$res=$this->user->get_address(); (Get the data in an array)
$config[‘center’] = “28.38,77.12”;  (You have to set the center of your map Latitude & Longitude of the place)
$config[‘zoom’] = ‘1’; (Set the map Zoom level from 1 to 10)
$this->googlemaps->initialize($config); (Initialize the Google map)

foreach($res as $maps) (For multiple marker run a foreach query)
{
$marker = array();
$marker[‘position’] = $maps->address; (Pass an array containing the N no. of locations)
$marker[‘infowindow_content’] =$maps->name; (Used only if you want name of place to gets poped up on clicking the marker)
$this->googlemaps->add_marker($marker);
}

$data[‘map’] = $this->googlemaps->create_map();
$this->load->view(‘geolocation’,$data); (Send all data to view)

}

  • Now lets’s pass on to our view file. In your view file just add 2 line of code which will get your code executed.

Use $map[‘js’] inside the head tag as it will help your map to get loaded.

Just paste $map[‘html’] anywhere inside the body tag and your map with multiple marker’s will get displayed.

2 Comments

  1. Hi, I read your blogs regularly. Your humoristic style is awesome, keep up the good work!

    Rating: 5.0. From 1 vote.
    Please wait...
    May 19, 2017
    Reply
    • Deepak Shah said:

      thankyou so much this is the only thing we need your love and support thankyou so much

      Rating: 5.0. From 1 vote.
      Please wait...
      May 21, 2017
      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *