Advertisement
AlexKr

Untitled

Jan 26th, 2021
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. <asp:HiddenField ID="latTextBox" OnValueChanged="Unnamed_ValueChanged" runat="server"/>
  2. <asp:HiddenField ID="lonTextBox" runat="server"/>
  3. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  4. <%if (!IsPostBack) { %>
  5. <script type="text/javascript" id="getCord">
  6. if (typeof navigator.geolocation === 'undefined') {
  7. alert("Geolocation services are not supported by your web browser");
  8. }
  9. else {
  10. navigator.geolocation.getCurrentPosition(handleLocation, handleError);
  11. }
  12.  
  13. function handleLocation(position) {
  14. var lon = position.coords.longitude;
  15. document.getElementById('<%= lonTextBox.ClientID %>').value = lon;
  16. var lat = position.coords.latitude;
  17. document.getElementById('<%= latTextBox.ClientID %>').value = lat;
  18. __doPostBack('lonTextBox', 'TextChanged');
  19.  
  20. }
  21.  
  22. function handleError(error) {
  23. switch (error.code) {
  24. case error.TIMEOUT:
  25. alert('Timeout');
  26. break;
  27. case error.POSITION_UNAVAILABLE:
  28. alert('Position unavailable');
  29. break;
  30. case error.PERMISSION_DENIED:
  31. alert('Permission denied');
  32. break;
  33. case error.UNKNOWN_ERROR:
  34. alert('Unknown error');
  35. break;
  36. }
  37. }
  38.  
  39. </script>
  40. <%} %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement