加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – jquery-gmap yii

发布时间:2020-12-13 22:44:11 所属栏目:PHP教程 来源:网络整理
导读:我正在使用此扩展程序 Yii Framework: Jquery-gmap 我是我的应用程序我使用了$gmap- updateMarkerAddressFromModel $标记 – capturePosition. 但是当使用$marker- capturePosition时,$gmap- updateMarkerAddressFromModel无效,否则$gmap- updateMarkerAddre
我正在使用此扩展程序 Yii Framework: Jquery-gmap
我是我的应用程序我使用了$gmap-> updateMarkerAddressFromModel& $标记 – > capturePosition.

但是当使用$marker-> capturePosition时,$gmap-> updateMarkerAddressFromModel无效,否则$gmap-> updateMarkerAddressFromModel在单独使用时工作正常.

我的代码

<?php
                Yii::import('ext.jquery-gmap.*');
                $gmap = new EGmap3Widget();
                $gmap->setSize(400,234);

                // base options
                $options = array(
                    'scaleControl' => true,'zoom' => 15,'center' => array(0,0),'mapTypeId' => EGmap3MapTypeId::ROADMAP,'mapTypeControlOptions' => array(
                        'style' => EGmap3MapTypeControlStyle::DROPDOWN_MENU,'position' => EGmap3ControlPosition::TOP_CENTER,),);
                $gmap->setOptions($options);

                // marker with custom icon
                $marker = new EGmap3Marker(array(
                            'draggable' => true,));
                $marker->address = 'London';
                $marker->capturePosition(
                    // the model object
                    $businessModel,// model's latitude property name
                    'lat',// model's longitude property name
                    'longi',array('drag')
                );
                // tell the gmap to update the marker from the model fields.
                $gmap->updateMarkerAddressFromModel(
                        // the model object
                        $businessModel,array('street','town','country'),array('zoom'=>16)
                );
                $marker->centerOnMap();
                $gmap->add($marker);
                $gmap->renderMap();
                ?>

解决方法

您没有初始化要传递给视图的模型.

因此,在将模型传递给视图之前,您需要添加
$businessModel = new BusinessModel()我假设这是你的类的名称以及它的引用.我再次假设模型类定义了正确的成员,即lat和long,稍后您将使用它.

看一下下面的例子:我们使用一个带有3个公共成员的地址,纬度,经度和缩放级别的示例

From the jquery-gmap plugin documentation:

Save Marker Position and Map Zoom to Yii Model

Allows capturing the latitude and longitude from a map marker,and the map’s zoom level,to a Yii model object. This is useful if you want to save additional information related to an address in your database.

Address model example :

class Address extends CActiveRecord
{
    public $latitude;
    public $longitude;
        public $mapZoomLevel;

    public function rules()
    {
            return array(
                array('latitude,longitude','numerical'),array('mapZoomLevel','numerical','integerOnly'=>true),);
    }
}

In your view file :

// init the model (usually passed to view)
$address = new Address();


// init the map
$gmap = new EGmap3Widget();
$gmap->setOptions(array('zoom' => 14));

// create the marker
$marker = new EGmap3Marker(array(
    'title' => 'Draggable address marker','draggable' => true,));
$marker->address = '10 Downing St,Westminster,London SW1A 2,UK';
$marker->centerOnMap();

// set the marker to relay its position information a model
$marker->capturePosition(
     // the model object
     $address,// model's latitude property name
     'latitude',// model's longitude property name
     'longitude',// Options set :
     //   show the fields,defaults to hidden fields
     //   update the fields during the marker drag event
     array('visible','drag')
);
$gmap->add($marker);

// Capture the map's zoom level,by default generates a hidden field
// for passing the value through POST
$gmap->map->captureZoom(
    // model object
    $address,// model attribute
   'mapZoomLevel',// whether to auto generate the field
   true,// HTML options to pass to the field
   array('class' => 'myCustomClass'),);

$gmap->renderMap();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读