嗨 iam javascript 和 google maps 新手,并尝试使用侧边栏实现简单的地图以下是我的代码
<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);
});
}
当前夜我单击侧边栏中的城市时,我会转到该地图并指向一个标记..我尝试过但缺少一些东西..任何帮助将不胜感激