【发布时间】:2012-01-24 08:41:58
【问题描述】:
到目前为止,我有一个可以从地址获取经度和纬度的隐蔽脚本。 问题是我不能提交,而提交按钮是用来获取经度和纬度的。
所以我想要以下内容: 地址将被放置在隐藏字段中。 (由我的 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>
【问题讨论】:
-
你好矩阵,我没有收到错误消息。如果我按原样使用上面的脚本,我会得到 long 和 lat。如果我从表单中删除“return false”,它正在提交但没有得到 long 和 lat。这就是为什么我想在页面加载时使用。 (我试过 .submit() 但没有任何运气)
标签: javascript latitude-longitude google-maps-api-2