Click here to Skip to main content
14,668,708 members
Rate this:
Please Sign up or sign in to vote.
See more: , +
How really get geolocation coordinates in aspx.cs as I know geolocation API is part HTML5 and whatever I studied till now only HTML and aspx(ASP.Net) can find geolocation.
But What is think is get the geolocation coordinates using aspx and then do my calculation on aspx.cs

Can anyone tell me how to get resultant coordinates to aspx.cs?

Thanks for ur help.

What I have tried:

<pre><!DOCTYPE html>

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
    <button onclick="getLocation()">Try It</button>

<p id="demo"></p>

    var x = document.getElementById("demo");

    function getLocation() {
        if (navigator.geolocation) {
        } else {
            x.innerHTML = "Geolocation is not supported by this browser.";

    function showPosition(position) {
        x.innerHTML = "Latitude: " + position.coords.latitude +
        "<br>Longitude: " + position.coords.longitude;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace Mobile_based_attendance_system
    public partial class display : System.Web.UI.Page
        public SqlDataReader reader;
        protected void Page_Load(object sender, EventArgs e)
            if (!IsPostBack)
                Page detail = (Page)Context.Handler;
                if (detail is login)
                    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ToString());
                    string query = "select * from employee,dept_data where per_no='" + ((login)detail).perno + "' and employee.dept_e=dept_data.dept";
                    SqlCommand cmd = new SqlCommand(query, con);
                    reader = cmd.ExecuteReader();

                        Label5.Text = reader["emp_name"].ToString();
                        Label6.Text = reader["deg"].ToString();
                        Label7.Text = reader["per_no"].ToString();
                        Label8.Text = reader["dept"].ToString();
        //Inside this I want to Compare Two Coordinates and occording to that i want to enable or disable the  required button
Updated 23-Dec-19 2:13am

Rate this:
Please Sign up or sign in to vote.

Solution 1

This article might help:

A Handy GPS Class [^]
Rate this:
Please Sign up or sign in to vote.

Solution 3

while you are going to do on comparison on aspx.cs page then first use WebMethod(Ajax Call)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100