Im new to JavaScript and new to combining languages. I want to use geolocation
's functions in my Java program and I believe this is the way to do it.
import javax.script.*;
public class Foo{
public static void main(String[] args) throws Exception {
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
engine.eval(new java.io.FileReader(args[0]));
}
}
JavaScript
var navigator ={};
var locater = function getLocation() {;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
}
};
//tell me how
locater();
Being new to JavaScript Im not sure how to do this.
I want to get the coordinates and print or possibly make it accessible to the Java program. If I should be using a different way to get my computer's location in a Java application please recommend a method because I cannot find one.