【问题标题】:API v3: Issue with GeoCoding service in Firefox 6.0 / IE 9.0API v3:Firefox 6.0 / IE 9.0 中的地理编码服务问题
【发布时间】:2011-12-18 17:26:56
【问题描述】:

我创建了一个代码来使用 GeoCoding 服务添加多个标记和 infoWindows。我已经从 API v3 Docs 复制了该方法。我的脚本从 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 上打开它时,相同的代码不起作用。

GeoCoding 服务为同一调用返回 ZERO_RESULTS。当我使用相同的地址调用该方法 5 次时,它能够添加标记。

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

在此先感谢...

苏迪尔

【问题讨论】:

  • 除此之外,我创建了带有地址的 DIV 块,并在 DIV 单击时添加了标记。这在 IE 8.0 中效果很好,但在 Firefox 6.0 中失败了。知道发生了什么,Google Maps API v3 如何根据浏览器表现不同?

标签: google-maps-api-3 geocoding google-geocoding-api


【解决方案1】:

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

        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);
            }
        });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-18
    • 2013-04-05
    • 1970-01-01
    • 2010-11-30
    • 1970-01-01
    • 2013-12-18
    • 1970-01-01
    相关资源
    最近更新 更多