我在 rails 3.2.12 中使用谷歌地图,我需要通过 infoWindow 为位置创建值更新纬度和经度值
如果我单击 map 上的任何标记,信息窗口将打开,并显示位置名称和两个按钮(“更新”和“删除”)单击更新时,当前信息窗口应关闭并打开显示在中的其他信息窗口的纬度和经度值文本字段。
请在下面找到我的代码
点击更新按钮,下面的函数应该调用
function getlocation(){
currentprojectid = $('#currentprojectid').val();
sid = $('#sessionid').val();
uid = $('#userid').val()
var locdata = {
userid: ,
sessionid: sid,
command: 'locationupdate',
projectid: currentprojectid
};
markersArray.push(marker);
currentmarker = marker;
var infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(marker, 'click', function(event){
infowindow.close()
infowindow.setContent("<p>LocatioName: <input id="country" type="text" value='+ address +'></p>\
<p>Longitude: <input id="lat" type="text" value='+ lattitude +'> </p>\
<p>Lattitude: <input id="long" type="text" value='+ longitude +'> </p>\
<p><input type="button" value="Save" onclick="saveLocation(currentprojectid)"/
<input type="button" value="Remove" onclick="removeMarker()"/></p>");
infowindow.open(map, marker);
});
currentmarker = marker;
var marker = new google.maps.Marker({
map: Gmaps.map.map,
position: new google.maps.LatLng(lattitude, longitude),
draggable: true
});
最佳答案
如果您从数据库中获取数据,则通过标记的 id 删除标记 试试这个代码..如果这对你有帮助:
<head>
<script src="js/jquery.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDMM9AqbeqIGxanHcZc9Ce3C9rRSRz6qvI&v=3.exp&libraries=places&sensor=false&"></script>
<script>
var map;
var marker;
var center = new google.maps.LatLng(21.0000,78.0000);
function initialize(){
var mapProp = {
center:center,
zoom:5,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("googleMap")
,mapProp);
var content = "<input type='button' id='click' value='add marker' />";
var infowindow = new google.maps.InfoWindow();
var marker = new google.maps.Marker({
position:center
});
marker.setMap(map);
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(content);
infowindow.open(map, marker);
// currentPopup = null;
});
}
</script>
</head>
<body onload="initialize()">
<div id="googleMap" style="height:500px; width:550px"></div>
<script>
$("body").on("click","#click",function(){
var mycenter = new google.maps.LatLng(24.0000,78.0000);
var marker = new google.maps.Marker({
position:mycenter
});
marker.setMap(map);
var infowindow = new google.maps.InfoWindow();
infowindow.setContent("am new");
infowindow.open(map,marker);
});
</script>
</body>
关于javascript - 使用 Javascript 更新纬度和经度值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17540705/