locked
how to get GPS coordinates to textbox RRS feed

  • Question

  • User1865404792 posted

    hi all

    I have this code to get GPS coordinates from the mobile phone to the asp page to the fields Textbox1 and Textbox2

    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=API_Key"></script>
     
    <script type="text/javascript">
        function ViewCoOrdinate() {
            if (navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(function (p) {
                    var lat = p.coords.latitude;
                    var lng = p.coords.longitude;
                    document.getElementById("txtLat").value = lat;
                    document.getElementById("txtLon").value = lng;
                });
            } else {
                alert('Geo Location feature is not supported in this browser.');
            }
      
            return false;
        }
            </script>
    
    <asp:TextBox ID="txtLat" runat="server" CssClass="auto-style14"></asp:TextBox>
    <asp:TextBox ID="txtLon" runat="server" CssClass="auto-style14"></asp:TextBox>
    <asp:Button ID="btnView" runat="server" Text="View" onclick="return ViewCoOrdinate()" />

    The following errors appear

    1- expected;

    2- identifier expected; 'return' is a keyword

    3- invalid expression term')'

    And all these mistakes from this line
    
    <asp:Button ID="btnView" runat="server" Text="View" onclick="return ViewCoOrdinate()" />

    Sunday, December 27, 2020 6:15 AM

Answers

  • User-474980206 posted

    In the code

    <asp:Button ID="btnView" runat="server" Text="View" onclick="return ViewCoOrdinate()" />

    onclick calls a sever routine (on postback processing). The value should be the name of an event delegate. You probably wanted onclientclick, which defines the JavaScript onclick event.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 27, 2020 8:12 PM