1
工作,我有谷歌地圖的腳本,以顯示與AJAX頁面上的地圖,我用jQuery的AJAX腳本分離的頁面上,那麼PHP腳本分隔頁也顯示谷歌地圖cordinates不會在阿賈克斯
我不會在主頁面上顯示谷歌地圖,但包含具有可見性的地圖的div:無css屬性。
這裏是在PHP頁面我的谷歌地圖的腳本:
`<?php
$host="host";
$username="user";
$passowrd="";
$db_name="db";
// Connect to my database and run query
mysql_connect($host,$username,$passowrd) or die("connect to database faild");
mysql_select_db($db_name) or die("ünable to connect to database");
$barcode = mysql_real_escape_string($_POST['barcode']);
// select data from tracking table
$query = "SELECT *
FROM `table`
WHERE `col` = '$barcode'";
$query2 = mysql_query($queryWatch);
$cor = mysql_fetch_assoc($2);
/* echo $cor['lat'];
echo $cor['lon']; */
echo "<script type='text/javascript'>";
echo "var stockholm = new google.maps.LatLng(".$cor['lat']. ",". $cor['lon'].");";
echo "var parliament = new google.maps.LatLng(".$cor['lat']. ",". $cor['lon'].");";
echo "var marker;";
echo "var map;";
echo "function initialize() {";
echo "var mapOptions = {";
echo "zoom: 15,";
echo "mapTypeId:
google.maps.MapTypeId.ROADMAP,";
echo "center: stockholm";
echo "};";
echo "map = new google.maps.Map
(document.getElementById('map_canvas'),";
echo "mapOptions);";
echo "marker = new google.maps.Marker({";
echo "map:map,";
echo "draggable:true,";
echo "animation: google.maps.Animation.DROP,
position: parliament
});
google.maps.event.addListener(marker,
'click', toggleBounce);
}
function toggleBounce() {
if (marker.getAnimation() != null) {
marker.setAnimation(null);
} else {
marker.setAnimation
(google.maps.Animation.BOUNCE);
}
}";
echo "</script>";
?>`
這裏是AJAX的腳本:
function get() {
$.post('fetch-map.php', {barcode: searchBarcode.barcode.value},
function(output) {
$('#mapContainer').html(output).show();
});
}
再次地圖容器的CSS屬性是知名度:沒有; 但地圖不起作用... 有什麼我想念...? 幫助將不勝感激
如果您使用[heredoc](http://us2.php.net/manual/en/language.types.string.php# language.types.string.syntax.heredoc)語法來輸出你的js。 –