Javascript 我想通过动态获取纬度&;从文本框中插入地址的经度
我已经为用户通过文本框输入指定的位置创建了代码(例如)。代码如下所示 我对这项技术一无所知,请尽你所能帮助我Javascript 我想通过动态获取纬度&;从文本框中插入地址的经度,javascript,google-maps,Javascript,Google Maps,我已经为用户通过文本框输入指定的位置创建了代码(例如)。代码如下所示 我对这项技术一无所知,请尽你所能帮助我 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=abcdefg&sensor=true_or_false"
type="text/javascript"></script>
<script type="text/javascript">
function geocoder(){
var place = document.getElementById("textarea").value;
geocoder = new GClientGeocoder();
geocoder.getLatLng(place, function(point) {
if (!point) {
alert(place + " not found");
} else {
var info = "<h3>"+place+"</h3>Latitude: "+point.y+" Longitude:"+point.x;
var map = new GMap2(document.getElementById("map_canvas"));
var x=map.setCenter(new GLatLng(point.y, point.x), 13);
map.setUIToDefault();
var marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(x);
}
});}
</script>
</head>
<body>
<table width="347" border="1" align="right">
<tr>
<td width="168"> </td>
<td width="163"> </td>
</tr>
<tr>
<td height="45"><div align="right">Address : </div></td>
<td><form id="form1" name="form1" method="post" action="">
<label>
<textarea name="textarea" id="textarea"></textarea>
</label>
</form>
</td>
</tr>
<tr>
<td><form id="form2" name="form2" method="post" action="">
<label>
<input name="Button" type="Button" id="Button" value="Submit" onClick="geocoder()" onunload="GUnload()"/>
</label>
</form>
</td>
<td> </td>
</tr>
</table>
<div id="map_canvas" style="width: 500px; height: 300px"></div>
</body>
</html>
无标题文件
函数geocoder(){
var place=document.getElementById(“textarea”).value;
geocoder=新的GClientGeocoder();
地理编码器。getLatLng(地点、功能(点){
如果(!点){
警报(位置+“未找到”);
}否则{
var info=“”+地点+”纬度:“+点y+”经度:“+点x;
var map=newgmap2(document.getElementById(“map_canvas”);
var x=地图设置中心(新玻璃(点y,点x),13);
map.setUIToDefault();
var标记=新的GMarker(点);
添加覆盖图(标记);
marker.openInfoWindowHtml(x);
}
});}
地址:
map.setCenter()不返回任何内容,也没有必要拆分“点”玻璃以便立即将其粘合在一起,以便更改此行
var x=map.setCenter(new GLatLng(point.y, point.x), 13);
到
改变这个
marker.openInfoWindowHtml(x);
到
.toUrlValue(5)调用只是将值舍入到小数点后5位。如果没有它,您可能会得到多达14个小数位,并且“point”已经在您想要的GLatLng副本上保存了函数闭包,所以您不需要“x”
marker.openInfoWindowHtml(x);
marker.openInfoWindowHtml(point.toUrlValue(5));