<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title>google地图标注记录经纬度</title> <script src="http://maps.google.com/maps?file=api&v=2.x&key=ABQIAAAAH4AcJsUkMn0IASG2YHiLyBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSTJOTVN2OpWo1TEFG3kkgGuVwRrA" type="text/javascript"></script> <script type="text/javascript"> var now_x = 117.03640937805176; var now_y = 36.71666428208896; var now_zoom = 14; function initialize() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map_canvas")); var center = new GLatLng(now_y, now_x); map.setCenter(center, now_zoom); var point = new GLatLng(now_y,now_x); var marker = new GMarker(point); map.addOverlay(marker); GEvent.addListener(map,"click", function(overlay,latlng) { var point = new GLatLng(latlng.y,latlng.x); // 根据经纬度创建点 var marker = new GMarker(point); // 创建标注 map.clearOverlays(); // 清除现有地图上的所有标注 map.addOverlay(marker); // 添加新标注 now_x = latlng.x; now_y = latlng.y; now_zoom = map.getZoom(); }); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); } } function submitpoint() { var message = document.getElementById("message"); message.innerHTML = "X:"+now_x+",Y:"+now_y+",ZOOM:"+now_zoom; } </script> </head> <body onload="initialize()" onunload="GUnload()"> <div id="map_canvas" style="width: 500px; height: 300px"></div> <div id="message"></div> <input type="button" onclick="submitpoint();" value="显示当前坐标" /> </body> </html>