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

时间:2014-06-26 08:48:21

标签: c# asp.net google-api

我必须通过我在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>

提前致谢

1 个答案:

答案 0 :(得分:0)

使用asp文本框

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

并在Javascript中使用

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

访问它。

使用

,没有asp文本框也可以
$get("txBoxId").value = x;