首页 > 解决方案 > 如何从 Asp Label.Text 加载航点坐标

问题描述

我在其中硬核值的第一个代码:

<script type="text/javascript">
    function myfunction() {
    var label3LatLng = 
document.getElementById('<%=TextBox1.ClientID%>').value;
      var label4LatLng = 
document.getElementById('<%=TextBox2.ClientID%>').value;
      
       
      L.Routing.control({
          waypoints: [
          L.latLng(21.5278654, 55.9196996), 
          L.latLng(23.5278654, 55.9196996) 

          ],
          routeWhileDragging: true,
          geocoder: L.Control.Geocoder.nominatim()
       
      }).addTo(map);
    }

输出:[![硬核输出][1]][1]

带有文本框或标签的代码:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

             <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>         
         
         
             <input type="button" onclick="myfunction()" value="Click Me" 
style="width:300px;">
            
        </td>
    </tr>
</table>

<div id="d1"></div>
<script type="text/javascript">
    function myfunction() {
    var label3LatLng = 
document.getElementById('<%=TextBox1.ClientID%>').value;
      var label4LatLng = 
document.getElementById('<%=TextBox2.ClientID%>').value;
      
       
      L.Routing.control({
          waypoints: [
          L.latLng(label3LatLng.trim()), // This assumes the label contains both latitude & longitude.
          L.latLng(label4LatLng.trim()) // Note: call trim to remove any potential whitespace.

          ],
          routeWhileDragging: true,
          geocoder: L.Control.Geocoder.nominatim()
       
      }).addTo(map);
    }

[![使用文本框输入时的输出][2]][2]

即使我在文本框警报消息中输入值显示值,但路由机器显示空值。[1]:https ://i.stack.imgur.com/x85v2.png [2]:https ://i.stack.imgur.com/7MzyC.png

标签: javascriptasp.netleafletleaflet-routing-machine

解决方案


推荐阅读