将 mysql 页面更改为 mysqli,现在谷歌地图 initMap 函数抛出错误


Changed a mysql page to mysqli and now the google maps initMap function is throwing an error?

我把这个页面改成了mysqli,并切换了数据库。我改变的只是连接和查询。

如果我删除查询,地图显示没有标记。

如果我添加查询,地图会消失并告诉我 initMap() 是未定义的。var_dump显示查询工作正常。

我做错了什么?这真的很奇怪。

提前感谢任何帮助。我最初从这里改编了代码

 var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/red.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: '<div style="color: #000">' + info + '</div>',
 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.HYBRID,
 mapTypeControl: true,
 mapTypeControlOptions: {
 style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
 },
 navigationControl: true,
 navigationControlOptions: {
 style: google.maps.NavigationControlStyle.DEFAULT
 }
 });
 <?php 
 $query = mysqli_query($dbc, "SELECT * FROM location");
 while ($row = mysqli_fetch_array($query)){
 $name=$row['name'];
 $addr1=$row['address'];
 $addr2=$row['address2'];
 $city=$row['city'];
 $state=$row['state'];
 $zip=$row['zip'];
 $country=$row['country'];
 $lat=$row['lat'];
 $lng=$row['lng'];
 echo ("addMarker($lat, $lng,'<p>". $name ."</p><br/>$addr2<br/>$city, $state $zip<br />$country');'n");
 }
 ?>
 center = bounds.getCenter();
 map.fitBounds(bounds);
 }
 </script>
 </head>
 <body onLoad="initMap()" style="margin:0px; border:0px; padding:0px;">
 <div class="container">
<?php 
var_dump($lat, $lng, $addr2);
?>
<div class="content">   
<h1 class="marked" align="left">
  <div id="child" >The Big Map</div></h1><br />

  <br/>
<div id="map"></div><br/>
</div>     
<br/>

问题是新数据库在纬度/液化天然气字段中具有 NULL 默认值。我将其更改为没有默认值(顺便说一句,它是一个浮点值)。感谢您的有用评论。

我们都知道,我是自学成才的,在编码知识方面存在巨大差距。如果有人想解释我的代码在哪里以及为什么可以更好,那么智慧将不胜感激,老师。