13

マーカーが表示されません。ドキュメントを読みましたが、問題が見つかりません。誰か助けてくれませんか?

ここにjsがあります:

function initialize() {
      var mapOptions = {
        center: new google.maps.LatLng(-8.064903, -34.896872),
        zoom: 16,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      };
      var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

      var marker = new google.maps.Marker({
          position: location,
          title:"Hello World!",
          visible: true
      });
      marker.setMap(map);
    }
4

1 に答える 1

37

私の推測では、あなたのlocationオブジェクトは定義されていません。マーカーの位置をマップの中心と同じ LatLng に設定してみて、機能するかどうかを確認してください。

function initialize() {
  latLng = new google.maps.LatLng(-8.064903, -34.896872)
  var mapOptions = {
    center: latLng,
    zoom: 16,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

  var marker = new google.maps.Marker({
      position: latLng,
      title:"Hello World!",
      visible: true
  });
  marker.setMap(map);
}
于 2013-02-22T14:33:01.537 に答える