Jump to content
Larry Ullman's Book Forums

Dynamically Update Google Map Based On User Query


Selvakumar
 Share

Recommended Posts

Hi, I am using this extension to display the google map in my page. And i have a text field that have been adding dynamically. I want to display the text field values in the google map. How to pass the text field values into the google map functionality.
view.php

<div id="map_section">
    <div class="country_travell" style="background-color: #F8F8F8">
    <?php
        foreach($countriesTravelled as $i => $countryTravelled) {
                $isCloseRequired = ($i==0) ? false : true;
                $this->renderPartial('_country_travelled', array('countryTravelled'=> $countryTravelled,
                        'i' => $i, // Row or iterator
                        'form'=>$form,
                        'isCloseRequired'=>$isCloseRequired));
        }
    ?>
</div>
        </div>
        <div id="gmap">
                <?php $this->renderPartial('gmap',array('flagMap1'=>$flagMap)); ?>
        </div>

_country_travelled.php

<div class="floatLeft txt-input" rel="col1" style="width:150px;">
        <?php
            echo $form->textField($countryTravelled, "[$i]place", array('onchange'=>'getPlaceName(this.value);', 'style' => 'width: 150px;'));
        ?>
</div>

script.js

function getPlaceName(vl) {
        alert(vl);

        $.ajax({
                type: 'POST',
                url: '<?php echo Yii::app()->createUrl("site/showGmap"); ?>',
                data:'place='+vl,
                        success:function(data) {
                                // alert(data);
                                // if success
                        $("#gmap").append(data);
                        jQuery("#gmap").load("<?php echo Yii::app()->createUrl('site/showGmap'); ?>");
                },
                        error: function(data) { // if error occured
                        alert("Error occured...! Please try again");
                },
                 dataType:'html'
        });

                // $("#gmap").load("gmap.php");
    }

Controller.php

public function actionShowGmap() {
        $place=$_POST["place"];
        // echo $place; exit;
        [b]$this->render('gmap', array('place'=>$place));[/b]
 }

In the controller i'm getting the value of place. and i want to pass the same place value in to the gmap.
Please anyone help me :(

Link to comment
Share on other sites

 Share

×
×
  • Create New...