1

作成したマップの 1 つにマーカーを追加する際に問題が発生しているようで、どこが間違っているのかわかりません。

地図は問題なくサイトに追加されており、たまたまマーカーを表示している方向コードも機能しています。

私が望むのは、この場合、学校がどこにあるかを表示する最初のマーカーであり、クリックすると住所を表示する情報ボックスがありますが、何を試しても表示されないようです。

すべての私のコードは次のとおりです:-

<div id="map_canvas" style="width:100%; height:392px;float:left;"></div>
  <div id="directionsPanel" style="float:left;max-width:395px; overflow:scroll;overflow-x: hidden;"></div>

            <script>
//define one global Object
  var myMap = {}
  //init 

  function initialize(){
  //set up map options
    var mapOptions = {
      center: new google.maps.LatLng(53.964304,-2.028522),
      zoom: 15,
      scrollwheel: false,
      mapTypeId: google.maps.MapTypeId.ROADMAP,

    };

    myMap.map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
    myMap.directionsService = new google.maps.DirectionsService();
    myMap.directionsDisplay = new google.maps.DirectionsRenderer();
    myMap.directionsDisplay.setMap(myMap.map);
    myMap.directionsDisplay.setPanel(document.getElementById("directionsPanel"));
  }//end init

  function createMarker(point, title, content, map) {
var marker = new google.maps.Marker({
position: point,
map: map,
title: title
});
var infowindow = new google.maps.InfoWindow({
content: content
});
google.maps.event.addListener(marker, 'click', function() {
if(curr_infw) { curr_infw.close();} // We check to see if there is an info window stored  in curr_infw, if there is, we use .close() to hide the window
curr_infw = infowindow; // Now we put our new info window in to the curr_infw variable
infowindow.open(map, marker); // Now we open the window
 });
 return marker;
  }

  //directions
  var calcRoute = function() {
    var start = document.getElementById("start").value,
    end = document.getElementById("end").value,
    request = {
        origin:start,
        destination:end,
        durationInTraffic :true,
        transitOptions: {
        departureTime:  new Date()
      },
      provideRouteAlternatives : true,
      travelMode: document.getElementById("travelmode").value
    };

    myMap.directionsService.route(request, function(result, status) {
      if(status == google.maps.DirectionsStatus.OK) {
        myMap.directionsDisplay.setDirections(result);
      }else{
       alert("something went wrong!");
      }
    });


  }
  //script loader
  var loadScript = function() {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "http://maps.googleapis.com/maps/api/js?key=AIzaSyDZsY0Xbo137bDtb8wmefTogdGl82QM85s&sensor=false&callback=initialize";
    document.body.appendChild(script);
  }
  window.onload = loadScript;

髪の毛を全部抜いてハゲになってしまう前に、この人たちの助けをいただければ幸いです笑。

ジェイソン

4

0 に答える 0