sirin k


0 notes

Gmap Multiploting and Capturing all marker updates in Yii

This article will be useful for those who are using jquery-gmap extension in Yii.

Here i am going to tell you how you can plot multiple locations in a single google map using this extension and how you can capture all marker locations when a user changing them.This will be useful when you are giving an option to mark multiple locations for a user and save all the updated locations in a single map.

i hope you already familiar with this extension and you are willing to store a single location through this extension.If you are not you can reffer one of my preveous article with this same extension(Google maps in Yii).

So you might have a location model which stores all the location of a business model.So you will be having ONE-TO-MANY relation from business to location  model.

Try the below code in your business create form.(_form.php)

// create a map centered in the middle of the world …
$gmap = new EGmap3Widget();
        ‘zoom’ => 14,
        ‘center’ => array(0,0),



foreach($model->locations as $loc)
//Initialize a marker
$m[$i] = new EGmap3Marker(array(
    ‘title’ => $loc->shop_name,
  //set location

/* add dragend event with an autogenerate js function(ie captureMarkerPosition()) */

 $m[$i]->addEvent(‘dragend’, ‘function(result){captureMarkerPosition’.$i.’(result);}’);

//add marker to gmap

/* generate hidden input fields to store locations */
echo “
<input type=’hidden’ name=’Location_id[]’ value=’”.$loc->id.”’ >
<input type=’hidden’ name=’Location_latitude[]’ id=’Location_latitude”.$i.”’ value=’”.$loc->latitude.”’>
<input type=’hidden’ name=’Location_longitude[]’ id=’Location_longitude”.$i.”’ value=’”.$loc->longitude.”’>
/*Generate individual functions to capture the marker position  */
echo ‘
<script type=”text/javascript”>
function captureMarkerPosition’.$i.’(marker)


}//end loop

Now we want to store all these captured positions when the user press the submit button.We can write a some code in the controller action.


                                  foreach($location[‘id’] as $id)
                                   $l->longitude =$location[‘longitude’][$i];

the above code will store the updated marker co-ordinates to Location model.


sirin k
Nintriva Wireless