我想从Gmap控件获取经度和纬度到文本框 [英] I want to get the latitude and longitude from the Gmap control into textboxes

查看:86
本文介绍了我想从Gmap控件获取经度和纬度到文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<%@ Register Src="~/GoogleMapForASPNet.ascx" TagName="GoogleMapForASPNet" TagPrefix="uc1" %>


html xmlns="http://www.w3.org/1999/xhtml" >
<head  runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1"  runat="server">
    <div>

 <uc1:GoogleMapForASPNet ID="GoogleMapForASPNet1"  runat="server" />
        <br />
        <asp:TextBox ID="TextBox1" runat="server">
        <br />
        <br />
        <asp:TextBox ID="TextBox2" runat="server">

    </div>
    <script type="text/javascript">

    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 2,
      center: new google.maps.LatLng(35.55, -25.75),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    google.maps.event.addListener(map, 'click', function(event) {
      if (event.latLng) {
        document.getElementById('textbox1').value = event.latLng.lat();
        document.getElementById('textbox2').value = event.latLng.lng();
      }
    });
    </script>
    </form>
</body>
</html>

推荐答案

您不能将服务器控件ID用作客户端ID.

这个:

You cannot use a server control id as a client id.

this:

document.getElementById(''textbox1'').value = event.latLng.lat();


之所以无法使用,是因为1.您使用服务器控件ID和2..即使可以使用,该ID还是区分大小写的.

要获取客户端ID,请加载页面,右键单击并使用查看源.另外,您可以在我认为的背后代码中设置ClientId属性.

希望对您有所帮助.


will not work because 1. You use the server control id and 2. Even if that would work, the id is case sensitive.

To get the client id, load the page, right click and use view source. Alternitavely, you can set the ClientId property in the code behind I think.

hope this helps.


这篇关于我想从Gmap控件获取经度和纬度到文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆