0
我到目前为止一个工作秘密脚本从一个地址得到经度和纬度。 问题是我无法提交,而提交按钮用于获取经度和纬度。谷歌地图api v2经度和纬度的地址问题
所以我想下面: 地址将被放置在一个隐藏的领域。 (由我的CMS,ExpressionEngine填充) 比页面加载的经度和纬度将收集在两个输入字段 比按提交和完成。
但是,如何做到这一点,我到目前为止使用了下面的代码。 请帮忙。
<!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>
<title>Longitude and Latitude from address</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=YOUR KEY" type="text/javascript" charset="utf-8">
</script>
<script type="text/javascript">
//<![CDATA[
function load() {
if (GBrowserIsCompatible()) {
geocoder = new GClientGeocoder();
}
}
function showAddress(geolocation) {
if (geocoder) {
geocoder.getLatLng(
geolocation,
function(point) {
if (!point) {
alert(geolocation + " not found");
} else {
document.geoform.longitude.value = point.x;
document.geoform.latitude.value = point.y;
}
}
);
}
}
//]]>
</script>
</head>
<body onload="load()">
<form action="#" name="geoform" id="geoform" onsubmit="showAddress(this.geolocation.value); return false">
<input type="hidden" name="geolocation" value="Address goes here, populated by cms" size="50" />
Decimal Longitude:
<input name="longitude" type="text" id="longitude" value="" />
Decimal Latitude:
<input name="latitude" type="text" id="latitude" value="" />
<input type="submit" value="Longitude/latitude codes" />
</form>
</body>
</html>
你会得到什么错误? – Unknown
Hello Matrix,我没有收到错误。如果我使用上面的脚本,我会得到长和经。如果我从表单中删除“返回false”,它会提交,但不会获得长和经。这就是我想在页面加载时使用的原因。 (我试过.submit()但没有任何运气) –