我如何使用用户输入坐标在谷歌地图上绘制多边形。我有两个输入字段(lat 和 lng),当用户单击按钮时,我想绘制多边形。我有这个代码,但它不起作用。谁能帮我?
HTML:
<form onsubmit="show(this.lat.value, this.lon.value); return false;">
<p><label>Latituda</label></p>
<input type="text" size="13" id="latbox2" name="lat" value="">
<p><label>Longituda</label></p>
<input type="text" size="13" id="lonbox2" name="lon" value="">
<p><input type="submit" id="button2" value="Show" class="btnsearch" ></p>
</form>
JavaScript:
function xz() {
if (GBrowserIsCompatible()){
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(43.500752, 16.435547), 6);
map.setUIToDefault();
map.addMapType(G_SATELLITE_3D_MAP);
map.enableGoogleBar();
}
}
function show(lat, lon){
var latOffset = 0.01;
var lonOffset = 0.01;
var polygon = new GPolygon([
new GLatLng(lat, lon - lonOffset),
new GLatLng(lat + latOffset, lon),
new GLatLng(lat, lon + lonOffset),
new GLatLng(lat - latOffset, lon),
new GLatLng(lat, lon - lonOffset)
], "#f33f00", 5, 1, "#ff0000", 0.2);
map.addOverlay(polygon);
}