4

私はこの拡張機能を使用していますYii Framework: Jquery-gmap Im my application I've used $gmap->updateMarkerAddressFromModel& $marker->capturePosition.

しかし、使用$gmap->updateMarkerAddressFromModelすると機能しません。$marker->capturePositionそれ以外$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();
                ?>
4

1 に答える 1

1

ビューに渡すモデルを初期化していません。

したがって、追加する必要があるビューにモデルを渡す前に $businessModel = new BusinessModel()、これがクラスの名前であり、それへの参照であると想定しています。繰り返しになりますが、モデル クラスには、後で使用する緯度と経度などの適切なメンバーが定義されていると想定しています。

以下の例を見てください: Address3 つの public メンバー、緯度、経度、ズームレベルを持つクラスを使用した例

jquery-gmap プラグインのドキュメントから:

マーカーの位置とマップのズームを Yii モデルに保存する

マップ マーカーから緯度と経度、およびマップのズーム レベルを Yii モデル オブジェクトにキャプチャできます。これは、住所に関連する追加情報をデータベースに保存する場合に便利です。

アドレスモデルの例:

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

あなたのビューファイルで:

// 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();
于 2012-06-28T13:38:21.743 に答える