我使用google api v3製作地圖。我在信息窗口中創建表單,點擊標記時出現。這裏是map.html如何在點擊標記時自動插入緯度和經度
<!DOCTYPE html >
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: Map Simple</title>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var marker;
var infowindow;
function initialize() {
var latlng = new google.maps.LatLng(-6.9667, 110.41677);
var options = {
zoom: 13,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map-canvas"), options);
var html = "<form action='save.php' method='post'>" +
"Title: <input type='text' name='title' id='title'/></br>" +
"Latitude: <input type='text' name='latitude' id='latitude'/></br>" +
"Longitude: <input type='text' name='longitude' id='longitude'/></br>" +
"Description: <input type='text' name='description' id='description'/></br>" +
"Category: <input type='text' name='category' id='category'/></br>" +
"<input type='submit' id='submit' value='Submit' /></br>" +
"</form>";
infowindow = new google.maps.InfoWindow({
content: html
});
google.maps.event.addListener(map, "click", function(event) {
marker = new google.maps.Marker({
position: event.latLng,
map: map
});
google.maps.event.addListener(marker, "click", function() {
infowindow.open(map, marker);
});
});
}
</script>
</head>
<body style="margin:0px; padding:0px;" onload="initialize()">
<div id="map-canvas" style="width: 500px; height: 300px"></div>
</body>
</html>
當標誌點擊,緯度經度&表格會自動填入,喜歡這幅畫
任何人都可以幫助我我想要的是什麼?感謝您的幫助
順便說一句 - 調整你的代碼中的空白,它看起來像後,你有內的另一個'listener'一個'listener'。我猜這不是你的意圖... – sfletche
是的,有聽衆在另一個聽衆裏面。我在監聽器中插入了一段代碼,但仍然無法工作 – user3506438