Q&A
Someone was asking me about doing a mobile web application ( for computers with locations services active and mobile browsers).. Did you ever want to find location on a webpage for use with a map control or just find the current latitude and longitude to use for more coding logic ?
There is a simple call so that you can access locations services from a page using JavaScript. For this example we will use positioning “one time access” call..
navigator.geolocation.getCurrentPosition
The JavaScript Function
function initiate_geolocation()
{
navigator.geolocation.getCurrentPosition(handle_geolocation_query, handle_errors);
}
With the aid of JQUERY this sample will show you how to make this happen in IE 9.. This method also works great with a number of mobile browsers (including Apple’s Mobile Safari)

Want to add location service to your page in HTML 5 compatible browser?
Here’s some example code.. This requires JQUERY to be installed..
Sample Source:
1: <!DOCTYPE html>
2: <html>
3: <head>
4:
5: <script src="jquery-1.5.1.js"></script>
6: <script>
7: jQuery(window).ready(function () {
8: jQuery("#btnInit").click(initiate_geolocation);
9: });
10:
11: function initiate_geolocation() {
12: navigator.geolocation.getCurrentPosition(handle_geolocation_query, handle_errors);
13: }
14:
15: function handle_errors(error) {
16: switch (error.code) {
17: case error.PERMISSION_DENIED: alert("user did not share geolocation data");
18: break;
19:
20: case error.POSITION_UNAVAILABLE: alert("could not detect current position");
21: break;
22:
23: case error.TIMEOUT: alert("retrieving position timed out");
24: break;
25:
26: default: alert("unknown error");
27: break;
28: }
29: }
30:
31: function handle_geolocation_query(position) {
32: alert('Lat: ' + position.coords.latitude +
33: ' Lon: ' + position.coords.latitude);
34: }
35: </script>
36: </head>
37: <body>
38: <div>
39: <button id="btnInit" >Find my location</button>
40: </div>
41: </body>
42: </html>
After entering the code you will see something like this when you click the find my location button. Internet Explorer will next ask you if it may access your currently reported position.

Then the system will come back with your currently reported coordinates.
