0

我有问题的 Google Map div 没有正确显示

<div id="g#arena.aid#" style="width: 600px; height: 300px; display: none"></div> 

不显示 - 代码显示地图是 div - 但未居中...未以标记为中心...

好像找不到解决办法。。。头疼。。。

所以列出竞技场的......希望隐藏他们的地图直到被调用......用图像调用:

    <img src="../images/gps1.png" height=25 border=0 alt="Show Map" 
           onclick="javascript:showElement('g#arena.aid#'); google.maps.event.trigger(document.getElementById('g#arena.aid#'),'resize');">

这是javascript - 可以很好地显示地图,但它没有以标记为中心......

地图需要主体加载...

  <body onload="initialize()">

  <script type="text/javascript">
    function initialize() {

    var #arena.aid#Latlng = new google.maps.LatLng(
        #arena.agpslat#,#arena.agpslong#);

    var #arena.aid#Options = {
        zoom: 15,
        center: #arena.aid#Latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    var map = new google.maps.Map(
        document.getElementById("g#arena.aid#"),
        #arena.aid#Options);

    var marker = new google.maps.Marker({
        position: #arena.aid#Latlng,
        map: map,
        title: '#JsStringFormat(arena.arenaname)#'
       });
    }

  google.maps.event.addDomListener(window, 'load', initialize);

  google.maps.event.trigger(map, 'resize');

  </script>

与此相关,此代码可以很好地显示地图-但不能居中标记-想法?

这是生成的脚本...显示完整地图 - 但未居中...

      <img src="../images/gps1.png" height=25 border=0 alt="Show Map" 
    onclick="javascript:showElement('gxoazormo'); google.maps.event.trigger(document.getElementById('gxoazormo'),'resize');">


   <div id="gxoazormo" style="width: 600px; height: 300px; display: none"></div>


    <script type="text/javascript">
      function initialize() {

    var xoazormoLatlng = new google.maps.LatLng(
        51.0914344788,-114.200531006);

    var xoazormoOptions = {
        zoom: 15,
        center: xoazormoLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    var map = new google.maps.Map(
        document.getElementById("gxoazormo"),
        xoazormoOptions);

    var marker = new google.maps.Marker({
        position: xoazormoLatlng,
        map: map,
        title: 'Bowness Sportsplex'
     });
    }

      google.maps.event.addDomListener(window, 'load', initialize);

google.maps.event.trigger(map, 'resize');

     </script>
4

1 回答 1

1
var currCenter = map.getCenter();
google.maps.event.trigger(map, 'resize');
map.setCenter(currCenter);

它居中...

于 2014-06-09T15:05:30.673 回答