简体   繁体   English

Google Maps API标记未放置

[英]Google Maps API markers not placing

I'm trying to place some markers on the map here but no luck. 我正在尝试在此处的地图上放置一些标记,但是没有运气。 Well actually it does show one marker which was called from the header as so: 好吧,实际上它确实显示了一个从标头中调用的标记,因此:

<script type="text/javascript"
  src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC5Hacj2nz6Uby-AeesTPo8JVH5uGOnwlc">
</script>
<script type="text/javascript">
var myCenter=new google.maps.LatLng(51.508742,-0.120850);
var map;
var markers;

function initialize()
{
var mapProp = {
    center:myCenter,
    zoom:5,
    mapTypeId:google.maps.MapTypeId.ROADMAP
    };

map=new google.maps.Map(document.getElementById("googleMap"),mapProp);

var marker=new google.maps.Marker({
    map: map,
    position:myCenter

});
}

google.maps.event.addDomListener(window, 'load', initialize);

</script>

that works, but when I try to add more markers, they don't come up. 可以,但是当我尝试添加更多标记时,它们不会出现。 I'm using php with it so the code I'm running looks like this: 我正在使用php,因此我正在运行的代码如下所示:

<?php

        global $wpdb;
            $results = $wpdb->get_results("SELECT * FROM REPORTS");

        foreach($results as $row){ ?>
            <script type="text/javascript">
                markers=new google.maps.Marker({
                    map:map,
                    position:new google.maps.LatLng(52,41)
                });
            </script>
        <?php
        } ?>

I should also mention that I'm using wordpress. 我还应该提到我正在使用wordpress。 This code checks out with no errors, and the echoes return a value so I don't know what it is, I started learning js/mysql last night. 这段代码没有错误地检出,并且回声返回一个值,所以我不知道它是什么,我昨晚开始学习js / mysql。 Thanks in advance! 提前致谢!

Change your approach a bit. 稍微改变你的方法。 Try reading out the data inside your JavaScript instead of creating a new script element for each marker. 尝试读取JavaScript内部的数据,而不是为每个标记创建一个新的脚本元素。 Then loop over this data with JavaScript to create the markers. 然后使用JavaScript遍历此数据以创建标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM