javascript - 我想使用数据库中的 map 标记

标签 javascript jquery google-maps

我有一张谷歌地图,我想在我的数据库中添加一个带有经纬度的新标记,但它不起作用,我发现了一些错误 “Uncaught SyntaxError: missing ) after argument list” 请告诉我。感谢您的帮助。

<!DOCTYPE html>
<html>
  <head>
  <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>

    <style>
       #map {
        height: 400px;
        width: 100%;
       }
    </style>
  </head>
  <body>
    <h3>My Google Maps Demo</h3>
    <div id="map"></div>
    <script>
      function initMap() {
            var mapOptions = {
                center: {lat: 13.847860, lng: 100.604274},
                zoom: 10,
            }
            var map = new google.maps.Map(document.getElementById('map'),mapOptions); 
            var marker, info;
            $.getJSON( "jsondata.php", funtion(jsonObj){
                $.each(jsonObj, function(i, item){
                    marker = new google.maps.Marker({
                        position: new google.maps.LatLng(item.lat, item.lng),
                        map: maps,
                    });
                    info = new google.maps.Infowindow();
                    google.maps.event.addListener(marker, 'click', (function(marker, i){
                        return function() {
                            info.setContent(item.name);
                            info.open(maps, marker);
                        }
                    })(marker, i));
                });
            });       
        }
    </script>
    <script async defer
    src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA6oLvZzDHD-qxeX3g17_uHQMWXFXCxU30&callback=initMap">

    </script>
  </body>
</html>

和我的连接文件

<?php
header('Content-Type: application/json');
$objConnect = mysqli_connect("localhost","root","root","username-databasename");
$strSQL = "SELECT * FROM markers ";
$objQuery = mysqli_query($objConnect,$strSQL);
$resultArry = arry();
while($obResult = mysql_fetch_assoc($objQuery))
{
    array_push($resultArray,$obResult);
}
echo json_encode($resultArray);
?>

/image/CLvCe.png

最佳答案

第24行错误,应该是这样的:

$.getJSON( "jsondata.php", funtion(jsonObj)){

关于javascript - 我想使用数据库中的 map 标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45980799/

相关文章:

javascript - 从传单 map 中删除图层

javascript - 是否可以使用 D3 创建按钮?

jquery - 添加 a.link 到 jquery .css

javascript - 谷歌地图 : Relative to Fixed Positioning

java - 如何定位谷歌地图标记?

javascript - Vue.js : form-data Event

javascript - 针对 HTML5 视频播放器优化的 Javascript

jquery - 如何处理标签点击+复选框点击?

ios - iOS:如何知道GMSMapView的缩放级别

javascript - Bluebird 的绑定(bind)方法在调用之间保存上下文(this)