1

My application is in spring-hibernate.I am also using spring mobile for mobile specific design,we want to trace the location of our user on web application so that it shows particular data.How can i get the location of mobile in spring application.Thanks

the code is from w3school:

<script>
var x=document.getElementById("demo");
function getLocation()
  {
  if (navigator.geolocation)
    {
    navigator.geolocation.getCurrentPosition(showPosition);
    }
  else{x.innerHTML="Geolocation is not supported by this browser.";}
  }
function showPosition(position)
  {
  x.innerHTML="Latitude: " + position.coords.latitude + 
  "<br>Longitude: " + position.coords.longitude; 
  }
</script>
  • how can mobile be trap by IP address. –  Sep 26 '13 at 04:35
  • OK. Perhaps it is unclear what are you asking about... Can you give more details about your web application? Do you mean your client get access to your web server by web browsers? – Serge P Sep 26 '13 at 05:22
  • yes, my application is in spring-hibernate it is about showing business opening times.If client access our website from mobile i want to get location of client. –  Sep 26 '13 at 05:40

1 Answers1

0

Ok. Let it be.(corrected after your comments)

You have next choice:

  • use browser GeoLocation API. (from client side using browser geolocation API)
  • use approximate location by IP address. (from server side)
  • create mobile application for your service (in your case you can try Phonegap framework). (from client side using native OS API)
  • use browser expoits (and getting access to mobile OS API) but it is illegal.

Geolocation API

User is asked for permissions to report location information to your server. So user has choice to deny access to location
After you get geo coordinates - you can send it to your server i.e. via ajax call.

$('#buttongeo').click(function(e) {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function(position) {
            $("#lat").val(position.coords.latitude);
            $("#lon").val(position.coords.longitude);
            // 
        }, 
        function(error) {
            alert('Error');         
        },{timeout:5000});
    }
    else{
        alert('no geolocation support');
    }
});

Example with markup on jsfiddle

Community
  • 1
  • 1
Serge P
  • 1,173
  • 3
  • 25
  • 39
  • how can i get the latitude and longitude of mobile device.I am trying for geolocation api but its not working. –  Sep 26 '13 at 13:01
  • @pragat thank you for GeoLocation API. I even don`t know about it – Serge P Sep 27 '13 at 05:32