php谷歌地图网站API javascript
我正在尝试让google maps for websites API在我的php网站上运行。 为此,我有一个php页面,为地图加载用户变量。 javascript在带有默认值的网页中运行良好,但我无法将$php变量加载到脚本中 也许一些javascript专家可以帮上忙php谷歌地图网站API javascript,javascript,php,google-maps,Javascript,Php,Google Maps,我正在尝试让google maps for websites API在我的php网站上运行。 为此,我有一个php页面,为地图加载用户变量。 javascript在带有默认值的网页中运行良好,但我无法将$php变量加载到脚本中 也许一些javascript专家可以帮上忙 function onProfileDisplay() { $user = CFactory::getRequestUser(); $document
function onProfileDisplay() {
$user = CFactory::getRequestUser();
$document =& JFactory::getDocument();
$document->addStyleSheet($css);
$my = CFactory::getUser();
$pluginParams = $this->params;
$param = new stdClass;
$param = $Lat = $pluginParams->get('Lat');
$param = $Lng = $pluginParams->get('Lng');
$param = $width = $pluginParams->get('width');
$param = $height = $pluginParams->get('height');
$param = $zoom = $pluginParams->get('zoom');
return '<body onload="onprofileDisplay()"> <div id="map_canvas" style="width:800px; height:500px"></div>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function onProfileDisplay() {
var latlng = new google.maps.LatLng(57.0442, 9.9116);
**var zoom = <?php echo ($zoom) ?>;**
var settings = {
**zoom: zoom,**
center: latlng,
mapTypeControl: true,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
navigationControl: true,
navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), settings);
var companyPos = new google.maps.LatLng(57.0442, 9.9116);
var companyMarker = new google.maps.Marker({
position: companyPos,
map: map,
title:"Some title"
});
}
</script>
';
}
函数onProfileDisplay(){
$user=CFactory::getRequestUser();
$document=&JFactory::getDocument();
$document->addStyleSheet($css);
$my=CFactory::getUser();
$pluginParams=$this->params;
$param=新的stdClass;
$param=$Lat=$pluginParams->get('Lat');
$param=$Lng=$pluginParams->get('Lng');
$param=$width=$pluginParams->get('width');
$param=$height=$pluginParams->get('height');
$param=$zoom=$pluginParams->get('zoom');
返回'
函数onProfileDisplay(){
var latlng=新的google.maps.latlng(57.0442,9.9116);
**var zoom=**
变量设置={
**缩放:缩放**
中心:拉特林,
mapTypeControl:true,
mapTypeControlOptions:{style:google.maps.MapTypeControlStyle.DROPDOWN_MENU},
导航控制:对,
navigationControlOptions:{style:google.maps.NavigationControlStyle.SMALL},
mapTypeId:google.maps.mapTypeId.ROADMAP
};
var map=new google.maps.map(document.getElementById(“map_canvas”),设置);
var companyPos=new google.maps.LatLng(57.0442,9.9116);
var companyMarker=new google.maps.Marker({
职位:companyPos,
地图:地图,
标题:“一些标题”
});
}
';
}
为了测试,我只尝试将php变量$zoom加载到javascript中,但它不起作用,
在javascript中:
var zoom = <?php echo ($zoom) ?>;
zoom: zoom,
var zoom=;
缩放:缩放,
但是,如果我将javascript更改为原始版本,它将不起作用
移除var zoom=;
缩放:15,
然后使用静态默认值工作
谢谢你的帮助
这是输出代码:
<script type="text/javascript">
function onProfileDisplay() {
var latlng = new google.maps.LatLng(57.0442, 9.9116);
var zoom = ".$zoom.";
var settings = {
".$zoom.":".$zoom.",
center: latlng,
mapTypeControl: true,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
navigationControl: true,
navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), settings);
var companyPos = new google.maps.LatLng(57.0442, 9.9116);
var companyMarker = new google.maps.Marker({
position: companyPos,
map: map,
});
}
</script>
函数onProfileDisplay(){
var latlng=新的google.maps.latlng(57.0442,9.9116);
var zoom=“.$zoom.”;
变量设置={
“$zoom.”:“$zoom.”,
中心:拉特林,
mapTypeControl:true,
mapTypeControlOptions:{style:google.maps.MapTypeControlStyle.DROPDOWN_MENU},
导航控制:对,
navigationControlOptions:{style:google.maps.NavigationControlStyle.SMALL},
mapTypeId:google.maps.mapTypeId.ROADMAP
};
var map=new google.maps.map(document.getElementById(“map_canvas”),设置);
var companyPos=new google.maps.LatLng(57.0442,9.9116);
var companyMarker=new google.maps.Marker({
职位:companyPos,
地图:地图,
});
}
原始代码如下所示:
public function onProfileDisplay() {
$user = CFactory::getRequestUser();
$document =& JFactory::getDocument();
$document->addStyleSheet($css);
$my = CFactory::getUser();
$pluginParams = $this->params;
$param = new stdClass;
$param = $api_key = $pluginParams->get('api_key');
$param = $Lat = $pluginParams->get('Lat');
$param = $Lng = $pluginParams->get('Lng');
$param = $width = $pluginParams->get('width');
$param = $height = $pluginParams->get('height');
$param = $zoom = $pluginParams->get('zoom');
return '<body onload="onProfileDisplay()">
<div id="map_canvas" style="width:800px; height:500px"></div
</body>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function onProfileDisplay() {
var latlng = new google.maps.LatLng(57.0442, 9.9116);
var zoom = ".$zoom.";
var settings = {
".$zoom.":".$zoom.",
center: latlng,
mapTypeControl: true,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
navigationControl: true,
navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), settings);
var companyPos = new google.maps.LatLng(57.0442, 9.9116);
var companyMarker = new google.maps.Marker({
position: companyPos,
map: map,
});
}
</script>';
}
}
?>
公共函数onProfileDisplay(){
$user=CFactory::getRequestUser();
$document=&JFactory::getDocument();
$document->addStyleSheet($css);
$my=CFactory::getUser();
$pluginParams=$this->params;
$param=新的stdClass;
$param=$api_key=$pluginParams->get('api_key');
$param=$Lat=$pluginParams->get('Lat');
$param=$Lng=$pluginParams->get('Lng');
$param=$width=$pluginParams->get('width');
$param=$height=$pluginParams->get('height');
$param=$zoom=$pluginParams->get('zoom');
返回'
为什么要将PHP放入从PHP->javascript返回的函数中?这似乎是一种获得结果的麻烦方法
无论如何,为什么不把PHP函数中的实际值放在那里呢?一旦它们在客户端的javascript中,你就不能使用服务器端的值了
例如:
函数onProfileDisplay(){
var latlng=new google.maps.latlng(57.0442,9.9116);
var zoom=“.$zoom.”
变量设置={
“$zoom.”:“$zoom.”,
中心:拉特林
感谢您的帮助,该脚本可以工作,但缩放值不是来自php,我使用document.write(zoom)对其进行了测试;输出是$zoom,而不是变量$zoomcode
var zoom=“.zoom.”的php值。var设置={.$zoom:“$zoom.”,center:latlng,code
您所做的更改实际上不会对脚本进行换行,google maps层显示为空,因为为zoom传递的值是$zoom,而不是php变量在输出上执行“查看源代码”并将其放入问题我保存了页面,从硬盘打开并控制+U,输出为在原始问题中.Thankschange this:var zoom=“.$zoom.”var settings={.$zoom.:“$zoom.”到this:var zoom='.$zoom.'.$zoom.;var settings={.$zoom.:'.$zoom.',