B4J Question [SOLVED] How to save jgooglemaps Polygon to file or Database?

Magma

Expert
Licensed User
Longtime User
If i use jsonparser to string....

Tried but getting this error:

Ths is from LOG(lst)
(ArrayList) [lat: 41.159012 lng: 23.518982, lat: 41.179688 lng: 23.642578, lat: 41.292254 lng: 23.624725, lat: 41.259227 lng: 23.514862, lat: 41.226183 lng: 23.480530]
'------
'This is the error:
main._convertpol_action (java line: 199)
netscape.javascript.JSException: SyntaxError: Unexpected token ':'. Expected either a closing ']' or a ',' following an array element.
at com.sun.webkit.dom.JSObject.fwkMakeException(JSObject.java:146)
at com.sun.webkit.WebPage.twkExecuteScript(Native Method)
at com.sun.webkit.WebPage.executeScript(WebPage.java:1509)
at javafx.scene.web.WebEngine.executeScript(WebEngine.java:1005)
at com.lynden.gmapsfx.javascript.JavaFxWebEngine.executeScript(JavaFxWebEngine.java:42)
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.objects.GoogleMapWrapper.AddPolygon(GoogleMapWrapper.java:516)
at b4j.example.main._convertpol_action(main.java:199)
at b4j.example.main._listview1_selectedindexchanged(main.java:316)
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:90)
at anywheresoftware.b4a.BA$1.run(BA.java:215)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:748)

B4X:
Sub convertpol_Action
Log(lst)
    pol=gmap.AddPolygon(lst,1,fx.Colors.Red,fx.Colors.Red,0.5)
end sub

lst is a list object...

I am generating json to string or pretty string...

B4X:
    Dim jp As JSONGenerator
    Dim sp As String
    'For k=0 To lst.Size-1      'here tried if was problem of commas... but was not...
    '    Dim sp As String=lst.Get(k)
    '    sp=sp.Replace(",",".")
    '    lst.Set(k,sp)
    'Next
    jp.Initialize2(lst)
    sp=jp.ToPrettyString(3)
    sql1.ExecNonQuery("UPDATE polygggons SET polytext='"&TextField1.Text.Trim&"', poly1='" & sp & "' WHERE myid= '" & ListView1.Items.Get(ListView1.SelectedIndex) &"';")

I am parsing with json the list...

B4X:
        Dim jp As JSONParser
        jp.Initialize(polys(Index))
        lst.Clear
        lst = jp.NextArray

but getting the error i said...

Is it possible with json or only with way you are saying ?
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
When i am doing this code (add positions to list) :
B4X:
Sub gmap_Click (Point As LatLng)
    mark(pnt)=gmap.AddMarker(Point.Latitude,Point.Longitude,"Point-"&(pnt+1))
    Dim newposition As LatLng
    newposition.Initialize(Point.Latitude,Point.Longitude)
    lst.Add(newposition)
    pnt=pnt+1
End Sub


then convertpol_action sub working / but when loading lst with json not convertpol_action sub ( pol=gmap.AddPolygon(lst,1,fx.Colors.Red,fx.Colors.Red,0.5) ) not works...
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
Just found the reason and the solution.

Is because the newposition is LatLng and when reading that list from db reading as string :-(

So the best way is to save 2 arrays that will be string with no problem (of lat and lng) and turn them in positions (latlng object)..
 
Last edited:
Upvote 0
Top