title: Want to get GPS coordinates in c# codebehind
body: <p>I'm having a bit of a problem with GPS coordinates. I'm able to get coordinates in asp.net / javascript using the geolocation, but need these to be available to a method in the c# codebehind. Unfortunately, for some reason the retrieved coordinates aren't, even if I put them into labels (they never end up there for some reason).</p>
  
  <p>So, what I'm thinking now is to try and get the coordinates (just need the latitude and longitude) directly into c# somehow, even if I have to run some javascript through c# (unsure how you do that).</p>
  
  <p>Does anyone have any ideas? I've posted the javascript below:</p>
  
  <pre><code>&lt;button id="btnLocate" runat="server" onclick="GetLocation()" style="width: 15%"&gt;Loc&lt;/button&gt;
  
          &lt;script type="text/javascript"&gt;
  
              function GetLocation()
              {
                  if (navigator.geolocation)
                  {
                      navigator.geolocation.getCurrentPosition(ShowPosition, ShowError, { maximumAge: 5000, timeout: 10000 });
                  }
                  else { alert("Geolocation is not supported by this browser."); }
              }
              function ShowPosition(position)
              {
                  var latdata = position.coords.latitude;
                  var londata = position.coords.longitude;
                  document.getElementById("lblLat").value = latdata;
                  document.getElementById("lblLon").value = londata;
              }
              function ShowError(error)
              {
                  if (error.code == 1)
                  {
                      alert("User denied the request for Geolocation.");
                  }
                  else if (error.code == 2)
                  {
                      alert("Location information is unavailable.");
                  }
                  else if (error.code == 3)
                  {
                      alert("The request to get user location timed out.");
                  }
                  else
                  {
                      alert("An unknown error occurred.");
                  }
              }
  
          &lt;/script&gt;
  </code></pre>