gpt4 book ai didi

javascript - 带有可点击侧边栏的 Google map

转载 作者:行者123 更新时间:2023-12-02 19:20:16 25 4
gpt4 key购买 nike

嗨,我是 javascript 和谷歌地图新手,尝试使用侧边栏实现简单的 map ,下面是我的代码

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

当晚我点击侧边栏 inee 中的城市转到该 map 并指向一个标记..我尝试过,但缺少一些东西..任何帮助将不胜感激

最佳答案

请参阅下面的示例,这是来自 Mike Williams 的 (v2) 教程的示例:

The Basics - Part 2: Adding a clickable sidebar

translated to v3

关于javascript - 带有可点击侧边栏的 Google map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12615000/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com