PHP不在地图上显示标记

时间:2017-09-15 03:34:17

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

所以我试图从我的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>

1 个答案:

答案 0 :(得分:0)

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

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