1

GeoCodingサービスを使用して、複数のマーカーとinfoWindowsを追加するコードを作成しました。APIv3ドキュメントからメソッドをコピーしました。私のスクリプトは、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回呼び出すと、マーカーを追加できます。

geoCodingサービスに新しいブラウザで問題があるかどうかについて何か考えはありますか?

前もって感謝します...

Sudhir

4

1 に答える 1

0

これは、マップを生成するために使用するコードです。必要に応じて調整できます。

        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);
            }
        });
于 2011-12-31T14:06:28.817 に答える