Bug? 2 Google map objects and polygons

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
I am developing an app where I need to define a geofence and some checkpoints.
To do this I am using 2 google map objects
Object 1 allows you to click to select the Geofence polygon
Object 2 allows you to click to select the checkpoints.

Is this actually possible with 2 google map object on B4j?

Background
I am using B4J 6.3 and jGoogleMaps Version 1.72
I have extracted the relevant code from my app to the sample program to demonstrate the problem.
Also, I have tried this with an APIkey for the map initalise and the same error occurs.

Problem 1. The LatLng object passed from MarkerClick does not appear to work with AddPolygon.

B4X:
Sub gmap_Click (Point As LatLng)
    Log($"$1.3{Point.Latitude} / $1.3{Point.Longitude}"$)
   
   
    Private pt As LatLng
    pt.Initialize(Point.Latitude,Point.Longitude)
    shape.Add(pt)
     
'    shape.Add(Point)
    ' If Point is used directly then an error occurs
    'netscape.javascript.JSException: ReferenceError: Can't find variable: LatLong45


    If (poly.IsInitialized) Then
        gmap.RemovePolygon(poly)
    End If
    poly = gmap.AddPolygon(shape,1,fx.Colors.Red,fx.Colors.Cyan,0.2)
End Sub

Using just shape.add(Point) causes the program to crash. on the gmap.addpolygonline with
netscape.javascript.JSException: ReferenceError: Can't find variable: LatLong45
Fix as shown above.

Problem 2. Showing another map causes AddPolygon to fail
  1. Run the attached program.
  2. Click a few of times on the map to draw a polygon
  3. Click on the choose button
  4. Immediately close this window (Note: you do not need to select a point on the new map)
  5. Click on the map again. A crash occurs with the following error:

netscape.javascript.JSException: ReferenceError: Can't find variable: LatLong46
Waiting for debugger to connect...
Program started.
Alert: Hide directions called
Alert: loadMapLibrary done
54.179 / 11.914
45.109 / 70.273
22.62 / 52.695
3.893 / 18.945
Alert: Hide directions called
Alert: loadMapLibrary done
20.659 / -5.312
Error occurred on line: 59 (Main)
netscape.javascript.JSException: ReferenceError: Can't find variable: LatLong46
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: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:533)
at b4j.google.map.main._gmap_click(main.java:214)
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:625)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168)
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.ShellBA.raiseEvent2(ShellBA.java:94)
at anywheresoftware.b4a.BA$1.run(BA.java:215)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(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$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)

Any ideas what could be causing this?
 

Attachments

  • SecondGooglemap.zip
    6.4 KB · Views: 231

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Just uncomment

shape.add(point)
and comment out the 3 lines above it. So should look like...

B4X:
'    Private pt As LatLng
'    pt.Initialize(Point.Latitude,Point.Longitude)
'    shape.Add(pt)
    
    shape.Add(Point)
 

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Ok, I will have to look at doing it a different way.

Is it possible to share the same Google Maps object across 2 windows?
 
Top