B4J Question B4j - Google Maps

Declan

Well-Known Member
Licensed User
Longtime User
I am trying to run the GoogleMaps example from:
I get no errors on compile, but no map is shown?
Must I get my own API Key?
 

Alexander Stolte

Expert
Licensed User
Longtime User
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
  1. https://console.cloud.google.com/pr...credentials?utm_source=Docs_Credentials&hl=en
  2. Create a new project
  3. Choose this project
  4. ...
I can only get as far as step 4 because I don't have a credit card saved in the google console.
But here is a video tutorial:
Thanks.
I have created an API Key and added:
B4X:
gmap.Initialize2("gmap",Null,"AIzaSyAEZ2xfst5HXEiikHJeyFkRUBJ7KhM_1Hc")
Rus same as before with Log:
B4X:
Alert: Hide directions called
mapLibraryLoaded!
No map displayed
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I downloaded the program from the forum.
It works with the original key in the program and it works also with your key in post#5.
Which program are you testing, the full or the light version.
In the full version add a break-point at line 169 joGMap = GMap
In the light version add a break-point at line 117 joGMap = GMap
Does the program reach this line ?
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
In the full version add a break-point at line 169 joGMap = GMap
In the light version add a break-point at line 117 joGMap = GMap
This is my full code, mush smaller than line 169?
B4X:
#Region  Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 400
#End Region

#PackagerProperty: IncludedModules = javafx.web
#PackagerProperty: AdditionalModuleInfoString = exports com.lynden.gmapsfx;    exports com.lynden.gmapsfx.javascript;    exports com.lynden.gmapsfx.javascript.event;
#PackagerProperty: AdditionalModuleInfoString = exports com.lynden.gmapsfx.javascript.object;    exports com.lynden.gmapsfx.service.directions;    exports com.lynden.gmapsfx.service.elevation;   
#PackagerProperty: AdditionalModuleInfoString = exports com.lynden.gmapsfx.service.geocoding;    exports com.lynden.gmapsfx.shapes;    exports com.lynden.gmapsfx.zoom;

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private Pane1 As Pane
    Private gmap As GoogleMap
    Private btnResetMap As Button
    Private btnJumpToEiffel As Button
    Private MarkerInfos As Map
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Show
    MainForm.RootPane.LoadLayout("1") 'Load the layout file.
    Dim options As MapOptions
    options.StreetViewControl = False
'    gmap.Initialize("gmap", options) 'You should call Initialize2 and set the API key!
    gmap.Initialize2("gmap",options,"AIzaSyAEZ2xfst5HXEiikHJeyFkRUBJ7KhM_1Hc")
    Pane1.AddNode(gmap.AsPane, 0, 0, Pane1.Width, Pane1.Height)
    MarkerInfos.Initialize
End Sub


Sub gmap_Ready
    btnResetMap.Enabled = True
    btnJumpToEiffel.Enabled = True
    For i = 1 To 10
        Dim m As Marker = gmap.AddMarker(10 * i, 10 * i, "Marker #" & i)
        AttachInfoWindow(m, "Some text " & i)
    Next
End Sub

Sub gmap_Click (Point As LatLng)
    Log($"$1.3{Point.Latitude} / $1.3{Point.Longitude}"$)
End Sub

Sub gmap_MarkerClick (SelectedMarker As Marker)
    ShowInfoWindow(SelectedMarker, gmap)
End Sub

Private Sub ShowInfoWindow (Marker As Marker, Map As GoogleMap)
    If MarkerInfos.ContainsKey(Marker) Then
        Dim info As JavaObject = MarkerInfos.Get(Marker)
        Dim jMap As JavaObject = Map
        jMap = jMap.GetField("map")
        info.RunMethod("open", Array (jMap, Marker))
    End If
End Sub

Private Sub AttachInfoWindow (Marker As Marker, Text As String)
    Dim infoWindow As JavaObject
    infoWindow.InitializeNewInstance("com.lynden.gmapsfx.javascript.object.InfoWindow", Null)
    infoWindow.RunMethod("setContent", Array (Text))
    MarkerInfos.Put(Marker, infoWindow)
End Sub

Sub btnResetMap_Action
    Dim cp As CameraPosition
    cp.Initialize(0, 0, 1)
    gmap.MoveCamera(cp)
End Sub

Sub Pane1_Resize (Width As Double, Height As Double)
    gmap.AsPane.SetSize(Width, Height)
End Sub

Sub btnJumpToEiffel_Action
    gmap.MapType = gmap.MAP_TYPE_SATELLITE
    Dim cp As CameraPosition
    cp.Initialize(48.858260, 2.29517, 18)
    gmap.MoveCamera(cp)
End Sub
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
Does the attached program work ?
I get the following Log:
B4X:
Waiting for debugger to connect...
Program started.
Alert: Hide directions called
mapLibraryLoaded!
Picked up _JAVA_OPTIONS: -Djava.net.preferIPv4Stack=true
This is the screenshot:
 

Attachments

  • GMapMini.png
    GMapMini.png
    24 KB · Views: 81
Upvote 0

klaus

Expert
Licensed User
Longtime User
And I get this.

WARNING: package com.sun.javafx.embed.swing.oldimpl not in javafx.swing
Waiting for debugger to connect...
Program started.
Alert: Hide directions called
mapLibraryLoaded!

Which version of Java do you use ?
I use this one in the paths setup : C:\Java19\bin\javac.exe
And which version of B4J ? I have version 10.00
And which version of the jGoogleMaps library, I have version 2.00
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
I am joining this party a bit late, but I about a week ago I tried running the forum example used here in Erel's GoogleMaps tutorial and got exactly the same result as reported in the current thread - ie . . .
Wait for
InitializeMap
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
*** mainpage: B4XPage_Resize [mainpage]
Alert: Hide directions called
mapLibraryLoaded!
. . . but no map showing. I gave up trying to find the problem. Since then I have got my own API key - when I have time I will try again.
 
Upvote 0
Top