2

我正在使用 rails 3.2.12 中的谷歌地图,我需要通过 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:&nbsp; <input id="country" type="text" value='+ address +'></p>\
              <p>Longitude:&nbsp;&nbsp;<input id="lat" type="text" value='+ lattitude +'> </p>\
            <p>Lattitude:&nbsp;&nbsp;<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
    });
4

1 回答 1

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&amp"></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>
于 2013-12-04T12:37:14.447 回答