我正在使用rails 3.2.12中的谷歌地图,我需要通过infoWindow更新纬度和经度值,以获取位置创建的值
如果我点击地图上的任何标记,infowindow将打开位置名称&两个按钮(“更新”和“删除”)点击更新时,当前的信息窗应关闭并打开文本字段中显示的其他窗口纬度和经度值。
请在下面找到我的代码
点击“更新”按钮,下面的功能应该调用
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
});
答案 0 :(得分:0)
如果您从数据库中提取数据,则通过标记的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>