简体   繁体   English

谷歌地图带有可点击的侧边栏

[英]Google maps with clickable sidebar

Hi iam javascript and google maps newbie and trying to implement simple maps with sidebar following is my code 嗨iam javascript和谷歌地图新手,并试图用侧边栏实现简单的地图是我的代码

    <script>
       function createMarker(lat,lng)
                {

    alert("lat,lang");
                  var marker = new google.maps.Marker({
                    map: map,
                    position: latlng,
                    content:content
                  });
                  if(icon){marker.setIcon(icon);}

                  if(center)
                  {
                    map.setCenter(latlng);
                  }

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

                  if(action)
                  {
                    action.fnc(map,action.args);
                  }
                  return marker;
              }
    </script>

<body>
<div id="container">
<div id="menu" style="background-color:#FFD700;height:800px;width:100px;float:left;">
<table border="0">
<tr>
<th>Cities</th>
</tr>
<tr>
<td onclick="createMarker('40.47','73.58');">newyork</td>
</tr>
<tr>
<td onclick="createMarker('41.50','87.83');">chicago</td>
</tr>

</table>
</div>


<script type="text/javascript">
        var map;
        var markersArray = [];

        function initialize()
        {
            var latlng = new google.maps.LatLng(12.9833, 77.5833);
            var myOptions = {
                zoom: 10,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);


            // add a click event handler to the map object
            google.maps.event.addListener(map, "click", function(event)
            {
                // place a marker
                placeMarker(event.latLng);
            });
        }

when eve i click the city in the sidebar inee to go to that map and point a marker..i tried but something missing..Any help would be Appreciated 当我点击侧边栏中的城市时,我会点击该地图并指向一个标记..我尝试了但是缺少了一些东西。任何帮助都会得到赞赏

See the example below, an example from Mike Williams' (v2) tutorial: 请参阅下面的示例,Mike Williams的(v2)教程中的示例:

The Basics - Part 2: Adding a clickable sidebar 基础知识 - 第2部分:添加可点击的侧边栏

translated to v3 翻译为v3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM