gpt4 book ai didi

php - 使用 Php 的谷歌地图显示不工作

转载 作者:行者123 更新时间:2023-11-30 13:11:32 25 4
gpt4 key购买 nike

我编写了一段代码,用于从数据库中获取纬度和经度值并将其显示在 map 中。

此代码在 Linux(Ubuntu) 中有效,但当我在 Windows 中运行时它不显示谷歌地图。请帮助我找到解决方案。

查看源信息:

   <?
$dbname ='test'; //Name of the database
$dbuser =''; //Username for the db
$dbpass =''; //Password for the db
$dbserver ='localhost'; //Name of the mysql server

$dbcnx = mysql_connect ("$dbserver", "$dbuser", "$dbpass");
mysql_select_db("$dbname") or die(mysql_error());
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<style type="text/css">
body { font: normal 10pt Helvetica, Arial; }
#map { width: 350px; height: 300px; border: 0px; padding: 0px; }
</style>
<script src="http://maps.google.com/maps/api/js?v=3&sensor=false" type="text/javascript"></script>
<script type="text/javascript">

var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/blue.png",
new google.maps.Size(32, 32), new google.maps.Point(0, 0),
new google.maps.Point(16, 32));
var center = null;
var map = null;
var currentPopup;
var bounds = new google.maps.LatLngBounds();
function addMarker(lat, lng, info) {
var pt = new google.maps.LatLng(lat, lng);
bounds.extend(pt);
var marker = new google.maps.Marker({
position: pt,
icon: icon,
map: map
});
var popup = new google.maps.InfoWindow({
content: info,
maxWidth: 300
});

google.maps.event.addListener(marker, "click", function() {
if (currentPopup != null) {
currentPopup.close();
currentPopup = null;
}
popup.open(map, marker);
currentPopup = popup;
});
google.maps.event.addListener(popup, "closeclick", function() {
map.panTo(center);
currentPopup = null;
});
}
function initMap() {
map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(0, 0),
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
},
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.SMALL
}
});



<?
$query = mysql_query("SELECT * FROM manu");
while ($row = mysql_fetch_array($query)){

$lat=$row['lat'];
$lon=$row['lon'];

echo ("addMarker($lat, $lon);\n");
}
?>
center = bounds.getCenter();
map.fitBounds(bounds);



}
</script>
</head>
<body onload="initMap()" style="margin:0px; border:0px; padding:0px;">
<div id="map"></div>
</html>

最佳答案

只是回应 addMarkers(... 不会调用它。

将那些函数调用包装在 $(document).ready() 中

http://docs.jquery.com/Tutorials:Introducing_$(document).ready()

$(document).ready(function() {
<?
$query = mysql_query("SELECT * FROM manu");
while ($row = mysql_fetch_array($query)){
$name=$row['name'];
$lat=$row['lat'];
$lon=$row['lon'];
$desc=$row['desc'];
echo ("addMarker($lat, $lon,'<b>$name</b><br/>$desc');\n");
}
?>
center = bounds.getCenter();
map.fitBounds(bounds);
});

关于php - 使用 Php 的谷歌地图显示不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13716940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com