12

これは基本的な問題だと思いますが、私は何度も頭を壁にぶつけてしまったので、誰かが私に同情してくれることを願っています!

次の例がありますが、灰色のボックスが表示され、マップがまったく表示されません。誰でも理由を教えてもらえますか?

実際に結果を返していることを確認しましたが、うまく機能しているようです。

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <style>
            html, body, #map-canvas {margin: 0;padding: 0;height: 100%;}
        </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
    <script>
      var geocoder;
      var map;

      function initialize() 
      {
        geocoder = new google.maps.Geocoder();        
        geocoder.geocode( { 'address': "England"}, function(results, status) 
        {
          if (status == google.maps.GeocoderStatus.OK) 
          {
            var mapOptions = {
              zoom: 8,
              center: new google.maps.LatLng(results[0].geometry.location),
              mapTypeId: google.maps.MapTypeId.ROADMAP
            }

            // Let's draw the map
            map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);

          } 
          else 
          {
            alert("Geocode was not successful for the following reason: " + status);
          }
        });
      }

    initialize();
    </script>
  </head>

  <body onload="">
 <div id="map-canvas" style="width: 320px; height: 480px;"></div>
</body>
</html>    
4

7 に答える 7

9

ブラウザ ウィンドウのサイズを変更し、ブラウザをシェイクするか、ブラウザ タブからカーソルでドラッグすると、マップが表示されます。

MVC 部分ビュー Google マップの奇妙な理由により、マップが空白になります。マップは機能しており、サイズを変更する必要があります。

ブラウザ ウィンドウをカーソルで揺らすのはおかしなことに聞こえますが、うまくいきます。

ありがとう、アヌラグ

================================================== =====================

私の最終的な作業コードは次のとおりです。

`

<script type="text/javascript">

    $(document).ready(function () {
        (function () {
            var options = {
                zoom: 6,
                center: new google.maps.LatLng(-2.633333, 37.233334),
                mapTypeId: google.maps.MapTypeId.TERRAIN,
                mapTypeControl: false
            };

            // init map
            var map = new google.maps.Map(document.getElementById('map_canvas'), options);


            var arrLocation = [];
            $("#markerDiv").find("div").each(function () {
                var Lat = $(this).find("input[id='Latitude']").val();
                var Lon = $(this).find("input[id='Longitude']").val();
                var Id = $(this).find("input[id='Id']").val();
                var AssessmentDet = $(this).find("input[id='AssessmentDateTime']").val();
                var LocAcc = $(this).find("input[id='LocationAccuracy']").val();
                var assessorName = $(this).find("input[id='AssessorName']").val();
                var partnerName = $(this).find("input[id='PartnerName']").val();
                arrLocation.push({
                    Id: Id,
                    Latitude: Lat,
                    Longitude: Lon,
                    AssessmentDate: AssessmentDet,
                    LocationAccuracy: LocAcc,
                    AssessorDetail: assessorName,
                    PartnerName: partnerName
                    });
            });

            var allMarkers = [];

            for (var i = 0; i < arrLocation.length; i++) {

                //final position for marker, could be updated if another marker already exists in same position
                var latlng = new google.maps.LatLng(arrLocation[i].Latitude, arrLocation[i].Longitude);
                var finalLatLng = latlng;
                var comparelatlng = "(" + arrLocation[i].Latitude + "," + arrLocation[i].Longitude + ")";
                var copyMarker = arrLocation[i];

                var marker = new google.maps.Marker({
                    position: new google.maps.LatLng(arrLocation[i].Latitude, arrLocation[i].Longitude),
                    map: map,
                    title: 'Equine # ' + arrLocation[i].Id,
                    icon:"abc.png"
                });


                var markerInfo = "Reference # : <b>" + arrLocation[i].Id + "</b><br/>";
                markerInfo = markerInfo + "Assessor : <b>" + arrLocation[i].AssessorDetail + "</b><br/>";
                markerInfo = markerInfo + "Date :  <b>" + arrLocation[i].AssessmentDate + "</b><br/>";
                markerInfo = markerInfo + "Partner :  <b>" + arrLocation[i].PartnerName + "</b>";(function (marker, i) {

  bindInfoWindow(marker, map, new google.maps.InfoWindow(), markerInfo);
                })(marker, i);
            }
        })();
    });

    function bindInfoWindow(marker, map, infowindow, html) {
        google.maps.event.addListener(marker, 'click', function () {
            infowindow.setContent(html);
            infowindow.open(map, marker);
        });
    }


</script>

`

于 2015-12-20T23:34:28.897 に答える
8

results[0].geometry.locationはすでに latLng オブジェクトなので、次のように言えます。

center: results[0].geometry.location

ここで動作するフィドルを見つけてください: http://jsfiddle.net/87z9K/

于 2013-08-29T12:02:43.183 に答える
2

これは、「google.maps.LatLng」が提供されているためです。座標のテストを提供すると、機能します。ラインを交換する

center: new google.maps.LatLng(results[0].geometry.location),

center: new google.maps.LatLng(-34.397, 150.644)

イングランド座標を取得する

于 2013-08-29T11:59:52.500 に答える
1

それはまさにあなたの問題ではありませんでしたが、密接に関連しています。

centre次のように、有効な で mapOptions を設定する必要があることがわかりました。

new google.maps.Map(mapCanvas, {
    center: new google.maps.LatLng(-34.397, 150.644)
});

マップ オプションを入力しなかった場合、または入力しても有効なcenterセットがなかった場合、タイルが読み込まれない空白のマップが表示されます。

于 2015-06-25T08:19:36.493 に答える