我的谷歌地图不会显示所有标记

发布于 2024-12-05 19:48:30 字数 2915 浏览 0 评论 0原文

嘿大家, 我需要用我们客户的标记制作一个谷歌地图 然而我在学校时并不擅长编程,并且没有真正获得太多编程:( 然而我的问题是,我能够在地图上获得一些标记,但不是全部,而且总是会显示不同的数量。我的工作地址不是基于纬度和经度。

这是我的脚本

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Maps JavaScript API Example</title>
    <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAjU0EJWnWPMv7oQ-jjS7dYxTPZYElJSBeBUeMSX5xXgq6lLjHthSAk20WnZ_iuuzhMt60X_ukms-AUg"
    type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[

        //load Google Map
        function load() {
          if (GBrowserIsCompatible()) {
                var map = new GMap2(document.getElementById("map"));
                var geocoder = new GClientGeocoder();
                map.addControl(new GLargeMapControl()); 
                map.addControl(new GMapTypeControl()); 

        //create randomnumber to prevent caching and retrieve xml file
        //data.xml vervangen door weg naar .xml bestand
        GDownloadUrl("data.xml", function(data, responseCode) {
        var xml = GXml.parse(data);

        //store markers in markers array
        var markers = xml.documentElement.getElementsByTagName("marker");

        //while loop ipv for loop
        var i = 0
        do
            {
            var address = markers[i].getAttribute("address");
            var html = markers[i].getAttribute("html");
            showAddress(map,geocoder,address,html);
            timer();
            }
        while (i <= 18);


            function timer()
        {
        i++
        setTimeout("timer()",1000);
        }

        //Create marker and set up event window
        function createMarker(point,html){
          var marker = new GMarker(point);
          GEvent.addListener(marker, "click", function() {
             marker.openInfoWindowHtml(html);
          });
          return marker;
        }

        //showAddress
        function showAddress(map,geocoder,address,html) {
          geocoder.getLatLng(
            address,
            function(point) {
              if (!point) {
                alert(address + " niet gevonden");
              } else {
                map.setCenter(point, 12);
                var marker = createMarker(point,html+'<br/><br/>'+address);
                map.addOverlay(marker);
              }
            }
          );
        }


          }
        ); //close GDownloadUrl
  } //close GBrowserIsCompatible
} //close load
   //]]>
    </script>
  </head>
  <body onload="load()" onunload="GUnload()">
    <div id="map" style="width: 1000px; height: 700px"></div>
  </body>
</html>

heey everybody,
i need to make a google map with the markers of our customers
however i'm not good at programming still at school and not really getting much programming :(
however my problem is that i'm able to get a few markers on the map however not all of them and it always is a different amount that will show. i'm working adress based not with lat and longtitude.

here is my script

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Maps JavaScript API Example</title>
    <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAjU0EJWnWPMv7oQ-jjS7dYxTPZYElJSBeBUeMSX5xXgq6lLjHthSAk20WnZ_iuuzhMt60X_ukms-AUg"
    type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[

        //load Google Map
        function load() {
          if (GBrowserIsCompatible()) {
                var map = new GMap2(document.getElementById("map"));
                var geocoder = new GClientGeocoder();
                map.addControl(new GLargeMapControl()); 
                map.addControl(new GMapTypeControl()); 

        //create randomnumber to prevent caching and retrieve xml file
        //data.xml vervangen door weg naar .xml bestand
        GDownloadUrl("data.xml", function(data, responseCode) {
        var xml = GXml.parse(data);

        //store markers in markers array
        var markers = xml.documentElement.getElementsByTagName("marker");

        //while loop ipv for loop
        var i = 0
        do
            {
            var address = markers[i].getAttribute("address");
            var html = markers[i].getAttribute("html");
            showAddress(map,geocoder,address,html);
            timer();
            }
        while (i <= 18);


            function timer()
        {
        i++
        setTimeout("timer()",1000);
        }

        //Create marker and set up event window
        function createMarker(point,html){
          var marker = new GMarker(point);
          GEvent.addListener(marker, "click", function() {
             marker.openInfoWindowHtml(html);
          });
          return marker;
        }

        //showAddress
        function showAddress(map,geocoder,address,html) {
          geocoder.getLatLng(
            address,
            function(point) {
              if (!point) {
                alert(address + " niet gevonden");
              } else {
                map.setCenter(point, 12);
                var marker = createMarker(point,html+'<br/><br/>'+address);
                map.addOverlay(marker);
              }
            }
          );
        }


          }
        ); //close GDownloadUrl
  } //close GBrowserIsCompatible
} //close load
   //]]>
    </script>
  </head>
  <body onload="load()" onunload="GUnload()">
    <div id="map" style="width: 1000px; height: 700px"></div>
  </body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离线来电— 2024-12-12 19:48:30

这可能是由于 Google API 限制了您可以进行的查询数量。如果您过快地要求它提供地址位置,那么它会在前几次请求后拒绝您。

我发现您尝试使用 timer() 函数来解决此问题,但您编写的方式实际上不会延迟 while 循环(Javascript 会设置计时器,然后愉快地继续循环的下一次迭代)。您需要做的是将 API 调用引入由 setTimeout 调用的代码中,如下所示:

function placeMarker(i) {

    var address = markers[i].getAttribute("address"),
        html = markers[i].getAttribute("html");

    showAddress(map,geocoder,address,html);

    if (++i <= 18) {

        setTimeout(
            function() {
                placeMarker(i);
            },
            1000
        );

    }

}

placeMarker(0);

This is likely due to the Google API throttling the number of queries you can make. If you ask it for locations of addresses too quickly then it will deny you after the first few requests.

I see you've tried to get around this with your timer() function, but the way you've written it won't actually delay the while loop (Javascript will set the timer then happily continue to the next iteration of the loop). What you need to do is bring the calls to the API inside the code that gets called by setTimeout, like this:

function placeMarker(i) {

    var address = markers[i].getAttribute("address"),
        html = markers[i].getAttribute("html");

    showAddress(map,geocoder,address,html);

    if (++i <= 18) {

        setTimeout(
            function() {
                placeMarker(i);
            },
            1000
        );

    }

}

placeMarker(0);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文