谷歌地图(它没有将结果显示到我的输入窗格中以保存到我的数据库中)
Google Maps(it is not showing the result into my input pane to save into my database)
问题是当我拖动标记时,它会将结果更新到div
中,但我不知道为什么它没有更新并在程序结束时显示在我的input
中。
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder = new google.maps.Geocoder();
function geocodePosition(pos) {
geocoder.geocode({
latLng: pos
}, function(responses) {
if (responses && responses.length > 0) {
updateMarkerAddress(responses[0].formatted_address);
} else {
updateMarkerAddress('Cannot determine address at this location.');
}
});
}
function updateMarkerStatus(str) {
document.getElementById('markerStatus').innerHTML = str;
}
function updateMarkerPosition(latLng) {
document.getElementById('info').innerHTML = [
latLng.lat(),
latLng.lng()
].join(', ');
}
function updateMarkerAddress(str) {
document.getElementById('address').innerHTML = str;
}
function initialize() {
var latLng = new google.maps.LatLng(21.0000, 78.0000);
var map = new google.maps.Map(document.getElementById('mapCanvas'), {
zoom: 5 ,
center: latLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var marker = new google.maps.Marker({
position: latLng,
title: 'Point A',
map: map,
draggable: true
});
更新当前位置信息。
updateMarkerPosition(latLng);
geocodePosition(latLng);
添加拖动事件侦听器。
google.maps.event.addListener(marker, 'dragstart', function() {
updateMarkerAddress('Dragging...');
});
google.maps.event.addListener(marker, 'drag', function() {
updateMarkerStatus('Dragging...');
updateMarkerPosition(marker.getPosition());
});
google.maps.event.addListener(marker, 'dragend', function() {
updateMarkerStatus('Drag ended');
geocodePosition(marker.getPosition());
});
}
加载处理程序以触发应用。
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<style>
#mapCanvas {
width: 800px;
height: 600px;
float: left;
}
#infoPanel {
float: left;
margin-left: 10px;
}
#infoPanel div {
margin-bottom: 5px;
}
</style>
<form method="POST" action="gsave.php">
<div id="mapCanvas"></div>
<div id="infoPanel">
<b>Marker status:</b>
<div id="markerStatus"><i>Click and drag the marker.</i></div>
<b>Current position:</b>
<div name="lat" id="info"></div>
<b>Closest matching address:</b>
<div name="address" id="address"></div>
</div>
<div id="map_canvas" style="background-color: #ffffff"></div>
<input type="text" id="info" name="lat" style="width:150px"> //i want to show in this input
<input type="text" id="address" name="address" style="width:150px">//and here also
<button type="submit" class="btn">Submit</button>
</form>
</body>
</html>
具有相同id
值的多个元素是无效的 HTML。更改脚本:
function updateMarkerAddress(str) {
document.getElementById('address').innerHTML = str;
document.getElementById('address_info').innerHTML = str;
}
function updateMarkerPosition(latLng) {
var latlng_out = [ latLng.lat(), latLng.lng() ].join(', ');
document.getElementById('info').innerHTML = latlng_out;
document.getElementById('latlng_info').innerHTML = latlng_out;
}
和您的元素:
<input type="text" id="latlng_info" name="lat" style="width:150px">
<input type="text" id="address_info" name="address" style="width:150px">
共享相同id
的所有其他元素也是如此。
相关文章:
- 如何使用默认的网络摄像头拍摄照片并将其保存在我的c#.net web应用程序中
- 我未保存的更改指令需要适用于具有不同名称的所有表单
- 如何从重定向的支付处理器网站提取交易详细信息并保存到我的rails 4数据库
- 在我的浏览器中用类似ctrl+s的PhantomJS保存一个网站
- 我的函数不会返回要保存在数组中的对象
- 在这个猫鼬独特的保存前验证中,我做错了什么
- 无法将所有位置值保存到我的数组中
- 我的jquery代码在谷歌chrome控制台中工作,而不是在保存它之后
- 我应该把维基百科的数据保存到我的数据库中吗
- 设置超时可以保存我的循环函数不被视为无响应
- 为什么我的保存时间功能不起作用?PHP + AJAX JS.
- 我的数据没有使用 AJAX 保存在数据库中
- 谷歌地图(它没有将结果显示到我的输入窗格中以保存到我的数据库中)
- 将我的 cookie 数据保存到 MySQL 数据库
- 我的文档何时使用猫鼬保存功能保存
- 浏览器保存了我的JavaScript函数名称并错误了我的网站
- wordpress网站页面上的Javascript在我尝试保存它时立即消失
- 如何在我的JavaScript中保存添加或删除类cookie
- 我如何修改我的保存功能,既保存用户/编辑用户
- OnBlur取消'这是我的保存事件