Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get geolocation server side.

Status
Not open for further replies.

M8KWR1

IS-IT--Management
Dec 8, 2008
20
GB
I have the following script to get the long and lat (after prompt, and they say ok), and it populates 2 hidden fields.

What I have trying to do is get this to server side so I have use the information a db query. I have tried to use a ontextchange event, but no event is firing!

Any assistance would be great - and thanks for looking.

Code:
                   <script>
                                $(document).ready(function () {
                                    if (true) { 

                                        navigator.geolocation.getCurrentPosition(getCoords);
                                    }
                                    else {

                                    }

                                    function getCoords(position) {

                                        $('#mobLat').val(position.coords.latitude);
                                        $('#mobLong').val(position.coords.longitude);
                                    }
                                });
        </script>
 
forum216

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
I do believe this question is more relevant to .net, as I want the longitude and latitude from the javascript to be accessible in my .net server side code.

If a java person does not have .net experience then surely they would not be able to assist me!
 
You can't get the geolocation info serverside. If you did, it would be the geolocaiton of the server, not the client machine.
What you can do, is run your code on the client, as it is, then pass the lat,lng to a handler(ashx) on the server side. You would call the handler with an AJAX call.
This is very simple to do using JQuery.
 
if you need geo location of your client you can use javascript and save location into hidden fields, and get tham from code behind
 
ou can't get the geolocation info serverside

Actually you can, from the server variables REMOTE_ADDR which has the IP of the requesting user agent

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Yes, but that is not the lat and lng which is geo location, IP is not geolocation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top