API v3:Firefox 6.0 / IE 9.0 中的地理编码服务存在问题

发布于 2024-12-12 13:06:31 字数 2053 浏览 0 评论 0原文

我创建了一个代码来使用地理编码服务添加多个标记和 infoWindows。我已经从 API v3 文档复制了该方法。我的脚本从 ASP.Net Web 服务中提取地址信息并将其写入隐藏的 div 元素。

      function codeAddress(address) 
  {
    //Get the location information from address
    geocoder.geocode( { 'address': address}, function(results, status) 
            {
                if (status == google.maps.GeocoderStatus.OK) 
                {
                    //Add a google marker onto the given address
                    var marker = new google.maps.Marker({
                            map: map,
                            animation: google.maps.Animation.DROP,
                            position: results[0].geometry.location
                    });

                //Prepare a infoWindow to display complete address
                var faddress = "<h4>Office Address:</h4><span>" + address + "</span>";
                var infowindow = new google.maps.InfoWindow({content: faddress});

                //Opening information window on mouseover event of marker
                google.maps.event.addListener(marker, 'mouseover', function(){
                    infowindow.open(map, marker);
                    }); 

                //closing the info window when mouse is moved out of marker
                google.maps.event.addListener(marker, 'mouseout', function(){
                    infowindow.close();
                    }); 

                } 
    });       
  }

下一段代码从隐藏的 div 元素中读取地址,并将标记与 InfoWindows 一起添加。此代码与 Internet Explorer 7.0/8.0 完美配合。

  //Populate the result onto div element
  $.each(arr,function(index, item){
    $(".result").append("<div class='block'>" + item + "</div>");                
  });

  //Loop through the div element and add marker to map
  $(".block").each(function(){
        codeAddress($(this).text());
   })

但是当我在 Firefox 6.0/IE 9.0 上打开它时,相同的代码不起作用。

对于同一调用,地理编码服务返回 ZERO_RESULTS。当我使用相同地址调用该方法 5 次时,它可以添加标记。

知道地理编码服务在新浏览器上是否有问题吗?

提前致谢...

苏迪尔

I have created a code to add multiple markers and infoWindows using the GeoCoding service. I have copied the method from API v3 Docs. My script pulls address information from a ASP.Net web service and writes them onto a hidden div element.

      function codeAddress(address) 
  {
    //Get the location information from address
    geocoder.geocode( { 'address': address}, function(results, status) 
            {
                if (status == google.maps.GeocoderStatus.OK) 
                {
                    //Add a google marker onto the given address
                    var marker = new google.maps.Marker({
                            map: map,
                            animation: google.maps.Animation.DROP,
                            position: results[0].geometry.location
                    });

                //Prepare a infoWindow to display complete address
                var faddress = "<h4>Office Address:</h4><span>" + address + "</span>";
                var infowindow = new google.maps.InfoWindow({content: faddress});

                //Opening information window on mouseover event of marker
                google.maps.event.addListener(marker, 'mouseover', function(){
                    infowindow.open(map, marker);
                    }); 

                //closing the info window when mouse is moved out of marker
                google.maps.event.addListener(marker, 'mouseout', function(){
                    infowindow.close();
                    }); 

                } 
    });       
  }

Next piece of code reads the address from hidden div elements and adds the marker along with InfoWindows. This code works perfectly with Internet Explorer 7.0/8.0.

  //Populate the result onto div element
  $.each(arr,function(index, item){
    $(".result").append("<div class='block'>" + item + "</div>");                
  });

  //Loop through the div element and add marker to map
  $(".block").each(function(){
        codeAddress($(this).text());
   })

But the same code is not working when i open it on Firefox 6.0/IE 9.0.

GeoCoding service returns ZERO_RESULTS for the same call. When I call the method 5 times with same address it is able to add markers.

Any idea if geoCoding service has issues with new browsers ?

Thanks in Advance...

Sudhir

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

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

发布评论

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

评论(1

故事与诗 2024-12-19 13:06:31

这是我用来生成地图的代码,您可以使用它并根据您的需要进行调整:

        var address = document.getElementsByTagName('address')[0].innerHTML;
        var title = document.getElementById('contact').getElementsByTagName('h2')[0].innerHTML;
        var geocoder;
        var map;
        geocoder = new google.maps.Geocoder();
        geocoder.geocode({ 'address': address },
        function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                var myOptions = {
                    zoom: 15,
                    center: results[0].geometry.location,
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                }
                map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
                var marker = new google.maps.Marker({
                    map: map,
                    position: results[0].geometry.location,
                    title: title
                });
            } else {
                alert("Geocode was not successful for the following reason: " + status);
            }
        });

this is the code im using to generate maps, you can take it and adjust it to your needs:

        var address = document.getElementsByTagName('address')[0].innerHTML;
        var title = document.getElementById('contact').getElementsByTagName('h2')[0].innerHTML;
        var geocoder;
        var map;
        geocoder = new google.maps.Geocoder();
        geocoder.geocode({ 'address': address },
        function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                var myOptions = {
                    zoom: 15,
                    center: results[0].geometry.location,
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                }
                map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
                var marker = new google.maps.Marker({
                    map: map,
                    position: results[0].geometry.location,
                    title: title
                });
            } else {
                alert("Geocode was not successful for the following reason: " + status);
            }
        });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文