【问题标题】:PHP not displaying markers on mapPHP不在地图上显示标记
【发布时间】:2017-09-15 03:34:17
【问题描述】:

所以我试图从我的 mysqli 数据库中的多个 GPS 坐标中显示 GPS 轨迹/图。我的 php 文件很好地显示了地图,但没有显示任何标记。有什么建议么?另外,既然我已经在问一个问题,有没有办法显示一条线而不是多个标记?

     <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: 600px; height: 600px; border: 0px; padding: 0px; }
 </style>

 <script src="http://maps.google.com/maps/api/js?key=myapikey&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
    });
 }

 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
        }
    });

<?php
 $sql = "SELECT * FROM gps_points WHERE email = '$email' AND gps_id = '$route_id'";
 $result = $link->query($sql);

 while ($row = mysql_fetch_array($result))
 {
    $lat=$row['e_lat'];
    $lon=$row['e_long'];
    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>

【问题讨论】:

  • 请提供一个minimal reproducible example 来证明该问题。我们没有您的数据库,但发送到浏览器的 HTML/Javascript/CSS(最小示例)可以工作。如果我从发布的代码中创建minimal reproducible exampleit works (fiddle)
  • @geocodezip 似乎我的 while 循环有问题,它没有触发,我知道那里有行,我做了$rowcount = mysqli_num_rows($result); echo "$rowcount";,它返回 27 行。

标签: php google-maps google-maps-api-3 mysqli gps


【解决方案1】:

好的,所以我的 while 循环有一个小错误,这是我的新 while 循环,它正在工作..

while($row = $result->fetch_assoc()) 
{
    $lat=$row['e_lat'];
    $lon=$row['e_long'];
    echo ("addMarker($lat, $lon);\n");
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-09
    • 1970-01-01
    • 1970-01-01
    • 2018-11-04
    • 2014-09-29
    • 2014-07-12
    • 2018-03-30
    相关资源
    最近更新 更多