B4J Question jGoogleMaps - Array of LatLng - gmap.AddPolyline - array parameter produce an error

amorosik

Expert
Licensed User
On jGoogleMaps example i have insert extra code to display a path of veichle
B4X:
Dim array_punti(1000) As LatLng
Dim count as long=0
Dim MyRs As ResultSet = MyDB.ExecQuery("select codice, latitudine, longitudine from LOGPERCORSI")

Do While MyRs.NextRow
    array_punti(count).Initialize(MyRs.GetDouble("latitudine"), MyRs.GetString("longitudine"))
    loop
   
gmap.AddPolyline( array_punti, 4, fx.Colors.Cyan)

When i start project, at runt time on ...AddPolyLine.... line, i get ths error
(AddPolyLine is ..... Errore nella linea: 374)
What I would like to do is load a LatLng array and then pass it to the AddPolyLine function
But not function correctly, why?
JGoogleMaps 1.82

B4X:
Waiting for debugger to connect...
Program started.
2020 09 16 14 38 48 659 - avvio AppStart
Get setting...
set 16, 2020 2:38:48 PM org.firebirdsql.logging.JulLogger warn
AVVERTENZA: WARNING: No connection character set specified (property lc_ctype, encoding, charSet or localEncoding), defaulting to character set NONE
MainForm_Resize
Alert: loadMapLibrary
mapLibraryLoaded!
Alert: !!!mapLibraryLoaded!!!
Errore nella linea: 374
netscape.javascript.JSException: SyntaxError: Unexpected identifier 'lat'. Expected either a closing ']' or a ',' following an array element.
    at com.sun.webkit.dom.JSObject.fwkMakeException(JSObject.java:156)
    at com.sun.webkit.WebPage.twkExecuteScript(Native Method)
    at com.sun.webkit.WebPage.executeScript(WebPage.java:1519)
    at javafx.scene.web.WebEngine.executeScript(WebEngine.java:1005)
    at com.lynden.gmapsfx.javascript.JavaFxWebEngine.executeScript(JavaFxWebEngine.java:59)
    at com.lynden.gmapsfx.javascript.JavascriptRuntime.execute(JavascriptRuntime.java:63)
    at com.lynden.gmapsfx.javascript.JavascriptObject.<init>(JavascriptObject.java:91)
    at com.lynden.gmapsfx.javascript.object.MVCArray.<init>(MVCArray.java:34)
    at anywheresoftware.b4j.googlemaps.GoogleMapWrapper.AddPolyline(GoogleMapWrapper.java:501)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:676)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:240)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:64)
    at starchild.osm.test.main._visualizza_percorso_mezzo(main.java:300)
    at starchild.osm.test.main._chk5_checkedchange(main.java:1215)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA$1.run(BA.java:216)
    at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:186)
    at java.lang.Thread.run(Thread.java:748)
 

Star-Dust

Expert
Licensed User
Longtime User
It must be a list not an array
1600275588185.png
 
Upvote 0

amorosik

Expert
Licensed User
First, you are not increasing Count in the loop.
Second, I've never used this stuff; post the link to the project ("jGoogleMaps example") or better, if you can, attach yours.

jGoogleMaps library with example

Obviously a count = count + 1 line is missing inside the loop

On example at link, there is an indication of how to add a path using the AddPolyline
But if you are loading a sequence of points from db, you don't know a priori how many they will be and so I thought of doing a loop to read the pairs of values inside a LatLng array
And then feed the arrary to the AddPolyline function
But it crashes the code, it shoots out the above error

Errore nella linea: 374
netscape.javascript.JSException: SyntaxError: Unexpected identifier 'lat'. Expected either a closing ']' or a ',' following an array element.
at com.sun.webkit.dom.JSObject.fwkMakeException(JSObject.java:156)
at com.sun.webkit.WebPage.twkExecuteScript(Native Method)
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Make it clear.
B4X:
Dim array_punti(1000) As LatLng
Dim count as Int = 0 '<--- why Long?

Dim MyRs As ResultSet = MyDB.ExecQuery("select codice, latitudine, longitudine from LOGPERCORSI")

Dim Lat, Lng As Double
Do While MyRs.NextRow
    Lat = MyRs.GetDouble("latitudine")
    Lng = MyRs.GetDouble("longitudine")
    array_punti(count).Initialize(Lat, Lng)
    Count = Count + 1
  Loop
 
gmap.AddPolyline( array_punti, 4, fx.Colors.Cyan)
 
Upvote 0

Carlos marin

Active Member
Licensed User
Longtime User
Hi

B4X:
Dim poligonos As List
poligonos.Initialize
Dim l1 As LatLng
l1.Initialize(Point.Latitude,Point.Longitude)
poligonos.Add(l1)


to add
B4X:
gmap.AddPolygon(poligonos,1,fx.Colors.Cyan,fx.Colors.Black,0.10)
 

Attachments

  • mapa.png
    mapa.png
    426.7 KB · Views: 232
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Hi

B4X:
Dim poligonos As List
poligonos.Initialize
Dim l1 As LatLng
l1.Initialize(Point.Latitude,Point.Longitude)
poligonos.Add(l1)


to add
B4X:
gmap.AddPolygon(poligonos,1,fx.Colors.Cyan,fx.Colors.Black,0.10)
Clipboard02.jpg


Belen ?


(I chose a very chaste photo)
(Edit by Erel: I removed this image. Not appropriate for this forum).
 
Last edited by a moderator:
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Hi

B4X:
Dim poligonos As List
poligonos.Initialize
Dim l1 As LatLng
l1.Initialize(Point.Latitude,Point.Longitude)
poligonos.Add(l1)


to add
B4X:
gmap.AddPolygon(poligonos,1,fx.Colors.Cyan,fx.Colors.Black,0.10)
sample AddPolygon figure. 7 points

latitude and longitude

the start point is equal to the end point, to close the polygon
 
Upvote 0
Top