Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to detect a mobile browser's GPS location? [duplicate]

I am making a web site targeted at mobile phones and would like to get the user's current GPS latitude/longitude when they visit my default page so I can show them results in their area. Is this possible using ASP.NET?

See Also

Get position data from mobile browser

like image 227
Frank Avatar asked Apr 17 '09 20:04

Frank


People also ask

Can browser detect location?

Your browser uses different types and sources of information to identify your location. These include your IP address, geolocation via HTML5 in your browser, and your PC's language and time settings.

How does Chrome determine location?

How Chrome shares your location. If you let Chrome share your location with a site, Chrome sends information to Google Location Services to get an estimate of where you are. Chrome can then share that info with the site that wants your location.

How can I get the current location of a user?

In order to get the current location of the user, we are going to use the getCurrentPosition() method which is available in the Navigator geolocation property. The getCurrentPosition() method is used for getting the current location of the user. Syntax: navigator.


2 Answers

Yes, you can do it with JavaScript and submit results back to server:

        function onPositionUpdate(position)
        {
            var lat = position.coords.latitude;
            var lng = position.coords.longitude;
            alert("Current position: " + lat + " " + lng);
        }

        if(navigator.geolocation)
            navigator.geolocation.getCurrentPosition(onPositionUpdate);
        else
            alert("navigator.geolocation is not available");
like image 133
Maksym Kozlenko Avatar answered Nov 14 '22 09:11

Maksym Kozlenko


There are services that will give you a location based on IP address. It won't be as precise as the GPS data but without having an application installed on the phone it may be as close as you are going to get.

like image 28
trent Avatar answered Nov 14 '22 10:11

trent