Php jquery gmap yi
我在用这个分机 我使用了Php jquery gmap yi,php,google-maps,yii,jquery-gmap3,Php,Google Maps,Yii,Jquery Gmap3,我在用这个分机 我使用了$gmap->updateMarkerAddressFromModel&$marker->capturePosition,这是我的应用程序 但是当使用$gmap->updateMarkerAddressFromModel时,$marker->capturePosition不起作用,否则单独使用时,$gmap->updateMarkerAddressFromModel工作正常 我的代码 <?php Yii::import('ext.jq
$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();
?>
您没有初始化要传递给视图的模型 因此,在将模型传递到视图之前,需要添加
$businessModel=new businessModel()
我假设这是类的名称以及对它的引用。我再次假设模型类定义了正确的成员,即稍后使用的lat和long
请看下面的示例:该示例使用一个类Address
,其中包含3个公共成员,纬度、经度和zoomlevel
保存标记位置并将地图缩放到Yii模型
允许捕获从地图标记到Yii模型对象的纬度和经度以及地图的缩放级别。如果要在数据库中保存与地址相关的其他信息,这将非常有用
地址模型示例:
在您的视图文件中:
执行$gmap->CapturePosition时,yii日志告诉您什么是$businessModel?你能给出代码吗?$businessModel可以。。这部分代码没什么好担心的。我需要的是问题的答案,而不是文档的解释:)是的,我已经初始化了业务模型
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();