Is it possible to detect a mobile browser's GP

2020-02-25 22:53发布

问题:

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

回答1:

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.



回答2:

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");


回答3:

Currently, GeoLocation API is highly available in modern smartphones.

See my answer to related question How to Get GPS location from the web browser. The solution is pure-javascript so it is server-technology-independent.



回答4:

You'd have to get security permission to access the appropriate GPS API. As long as you know the API, you'll be able to obtain the appropriate data, but it'll depend on the OS. I know it is accessible via Python as PyS60 for Nokia phones.



回答5:

You're not going to have much luck at the moment, but this is something that should be possible within a few years. The W3C have published a Geolocation API Draft, and this has been implemented into a jailbreak iPhone app called Locatable, but support is going to be so few and far between it's not worth the implementation time!