Welcome Guest, Not a member yet? Register   Sign In
Question on infowindow_content of Google Map API V3

Hello everyone, currently I am working on a project of map search.
I am using the google map library from Steve (http://biostall.com/codeigniter-google-m...pi-library)

It's really great library. However, I faced with two problems. I will be very pleased if you can help me.

1. I tried to add the hyperlink into info_window, but it can't be worked, no google map shown.
$marker['infowindow_content']='<a href="http://www.google.com">Google</a>'

However, when I changed to
$marker['infowindow_content']='<h1>Hello World</h1>'
The map showed and the info_window works.

How can I add the hyperlink into info_window by a correct way?

2. I have several shop address at the same building that is using the same latitude and longitude.
How can I show their info on the same $infowindow_content?

Currently, I am using the code:

foreach ($query->result() as $row) {
echo $row->shop_name; echo “”;
echo $row->lat,$row->lng; echo “”;
$marker['position'] = $row->lat.’,’.$row->lng;

However, the old infowindow_content will be replaced by new infowindow_content using this method. Any idea of how can we show multi-information into the same infowindow when using the same latitude and longitude?

Thanks so so much in advance.

Hi Desmond,

Thanks for using my library. I hope it's working OK for you. Please find below the answers to your questions:

1. Adding a link to an infowindow
The problem here is your using double quotes which, if you view the source of your page, you'll see need to be escaped. Admittedly the library should handle this so I'll add this in as an amendment and put a new version up for download.

In the meantime you can get around this by swapping you single quotes for double quotes and your double quotes for single quotes. I did try and put an example here but it kept getting stripped...

2. Multiple markers at the same location
This is a bit more tricky. If it was me however I would recommend trying something like so:

// get your list of shop addresses from the database ordered by 'lat' primarily, then 'lng'
$this->db->order_by("lat", "asc");
$this->db->order_by("lng", "desc");
$query = $this->db->get();

// Set up this variable to keep track of the lat/lng previously used
// You'll see this in action below
$previousLatLng = '';

// Set up this variable to keep track of the shop names belonging to a single lat/lng
$shopNames = '';

// loop through shops returned from the query above
$marker = array();
foreach ($query->result() as $row) {
   $thisLatLng = $row->lat.','.$row->lng;
   // if this isn't the first iteration and isn't the same lat/lng as the previous shop
   // add the marker to the map
   if ($previousLatLng!="" && $previousLatLng!=$thisLatLng) {
      $marker['position'] = $thisLatLng;
      $marker['infowindow_content'] = $shopNames;

      // reset shop names as we're now moving onto a new lat/lng
      $shopNames = '';
   $shopNames .= $row->shop_name.'<br />';

   // set this so we know what the last shops lat/lng was during the next iteration
   $previousLatLng = $thisLatLng;


// add a marker for the last shop that wouldn't have been dealt with yet in the above code
if (isset($marker['position'])) {

I haven't tested that code so no doubt some amendments will be needed but it should put you on the right path.

Give me a shout if I can be of any more help Smile

Good luck!


Thanks so so much, Steve.

It works perfectly !! You save my life ! :lol:

Really great works and logic, please keep going ;-)

I do very enjoy using your library, it's simple to use and working very well.

Hi Steve, I have one more question but it's not codeIgniter, it's about SQL.
I am a newbie. Sorry for keep asking questions.
I have searched the solution for two days. I will be very grateful if you can help me.

In my phpmyadmin SQL database, I have hundreds of Google map URL. I want to change them into lag and lng automatically.

For example:

How can I write a SQL instruction to extract lag and lng out of it?
Seems all lag and lng are after & ll=
In the example: &ll=22.279429,114.181622

Thanks so much if anyone could help ;-)

Theme © iAndrew 2016 - Forum software by © MyBB