【问题标题】:Update Latitude & Longitude values using Javascript使用 Javascript 更新纬度和经度值
【发布时间】:2023-03-26 08:29:01
【问题描述】:

我正在使用 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
    });

【问题讨论】:

    标签: javascript ruby-on-rails-3 google-maps-markers


    【解决方案1】:

    如果您从数据库中获取数据,则通过标记的 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多