繁体   English   中英

如何在asp.net中通过文本框设置经度和纬度位置?

[英]How can I set Longitude and Latitude Positions by textboxes in asp.net?

我必须通过在body标签中定义的文本框获取经度和纬度位置,并且应该在javaScript中定义的经度和纬度变量中设置文本框的值。 此代码未在JavaScript中的经度和纬度变量中设置文本框值。 谁能帮我?

My Code:    

     <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC6v5-2uaq_wusHDktM9ILcqIrlPtnZgEk&sensor=false"></script>

        <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>

        <script type="text/javascript">

            if (navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(success);
            } else {
                alert("Geo Location is not supported on your current browser!");
            }

                    **latitude** = document.getElementById('latitude').value; //position.coords.latitude;

                    **longitude** = document.getElementById('longitude').value; //position.coords.longitude;

            function success(position) {
                **latitude** = document.getElementById('latitude').value; //position.coords.latitude;
                **longitude** = document.getElementById('longitude').value; //position.coords.longitude;
                var city = position.coords.locality;
                var myLatlng = new google.maps.LatLng(latitude, longitude);
                var myOptions = {
                    center: myLatlng,
                    zoom: 12,
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                };

                var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

                var marker = new google.maps.Marker({
                    position: myLatlng,
                    title: "lat: " + latitude + " long: " + longitude
                });

                marker.setMap(map);
                var infowindow = new google.maps.InfoWindow({ content: "<b>Your Latitude Position: </b>" + latitude + "<br /><b>Your Longitude Position: </b>" + longitude + "" });
                infowindow.open(map, marker);
            }

            function SetValues() {
                **latitude** = document.getElementById('latitude').value; //position.coords.latitude;
                **longitude** = document.getElementById('longitude').value; //position.coords.longitude;
            }

        </script>
        </head>


        <body>
            <form id="form1" runat="server">

            Latitude Position:
     <input type="text" id="latitude" value="" PlaceHolder="Enter Latitude Position"/>

    Longitude Position: <input type="text" id="longitude" value="" PlaceHolder="Enter Longitude Position"/>

    <input type="submit" value="Set" onclick="SetValues()" />

          <div id="map_canvas" style="width: 500px; height: 400px"></div>

            </form>
        </body>
        </html>

提前致谢

使用asp文本框

<asp:TextBox ID="txBox" runat="server" />  

并在Javacript中使用

$get("<%=txBox.ClientID %>").value = x;

访问它。

也可以通过使用asp Textbox而不使用它

$get("txBoxId").value = x;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM