Google地图标记,添加的路线代码未显示

时间:2013-04-19 10:41:59

标签: google-maps google-maps-markers

我似乎无法在我创建的某个地图上添加标记,而我似乎无法弄清楚我在哪里出错了。

地图已被添加到网站上,我甚至可以使用方向代码正常显示标记。

我想要的是一个初始标记,显示在哪里,在这种情况下,学校是一个信息框点击显示地址,但我似乎无法显示无论我尝试什么

我的所有代码如下: -

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

对于这些家伙的任何帮助都会非常感激,然后我最终变得秃顶拔出我的头发大声笑。

杰森

0 个答案:

没有答案