1

I found a great js code that gives a precise GPS coordinate without using any gps sensor. In some documentations, I've learned that this is due to the usage of w3c geolocation standard.

The code is,

function getLocation() {
    if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
} else { 

}
}

function showPosition(position) {
console.log(position.coords.latitude + 
"<br>Longitude: " + position.coords.longitude); 
}

It works perfect on chrome, although not in IE.

My issue is that I want to use the result of this source in my java application. Since I'm not good at javascript, I don't know what to do.

How can I retreive the result of this source?

March3April4
  • 2,131
  • 1
  • 18
  • 37

1 Answers1

0

You can run Javascript in a Java application using Nashorn or Rhino libraries.

But your script will not work since navigator.geolocation is an object provided by the browser environment which does not exist in Java based JS environments.

You should search for Java based geolocation library instead. This could be a starting point.

wero
  • 32,544
  • 3
  • 59
  • 84