How to get the position (latitude and longitude) of a map in a WebBrowser component when pressed click

50 views
Skip to first unread message

rube...@yahoo.com

unread,
May 22, 2016, 1:02:01 AM5/22/16
to CodenameOne Discussions
hi,

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?

Shai Almog

unread,
May 23, 2016, 12:09:18 AM5/23/16
to CodenameOne Discussions, rube...@yahoo.com
Hi,
that's more of a JavaScript question than a Codename One question and that's not one of our stronger suits.

rube...@yahoo.com

unread,
May 24, 2016, 2:31:04 PM5/24/16
to CodenameOne Discussions, rube...@yahoo.com
Hi,

Mr Steve, will have some solution to my problem
Reply all
Reply to author
Forward
0 new messages