I show a map using html with WebBrowser component.
I created a javascript in the html code with the intent to load the values of the latitude and longitude is given every time a click on the map.
HTML code:
Javascript Function
function Taxi(nombre, latitud, longitud) {
this.nombre = nombre;
this.latitud = latitud;
this.longitud = longitud;
}
Code to call the function in HTML:
// Adiciona un listener (escucha) para evento click
google.maps.event.addListener(poligono, 'click', showPoligono);
}
function showPoligono(event) {
var desc = this.desc;
datos = new Taxi(desc, event.latLng.lat(),event.latLng.lng());
}
My intention is to load the global variable "data" every time the "click" event runs on the map
Codename one Code:
// Show Map
webBrowser = new WebBrowser() {
@Override
public void onLoad(String url) {
Component c = getInternal();
if (c instanceof BrowserComponent) {
BrowserComponent b = (BrowserComponent) c;
// Envía parametros al html
String mes = new String();
b.execute("mapa('" + mes + "')");
}
}
};
webBrowser.setURL("jar:///mapa.html");
// Listen position
final BrowserComponent c = (BrowserComponent) webBrowser.getInternal();
final JavascriptContext ctx = new JavascriptContext(c);
c.addWebEventListener("onLoad", new ActionListener() {
public void actionPerformed(ActionEvent evt) {
JSObject pageContent = (JSObject) ctx.get("datos");
Dialog.show("Content", pageContent.getString("nombre") + " " + pageContent.getString("latitud")+ " " + pageContent.getString("longitud"), "OK", "Cancel");
}
});
As I make this work?