B4J Question Marker on Googlemaps

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All,

I am trying to add 2 markers to Googlemaps using The Googlemaps example.
Attached is the screen print of the IDE and the resulting error. Below is the code.
It appears that the IDE see's that the marker MarkerName1 needs to be initialized, there is no Initialize member. ??

B4X:
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 markerMap As Map
    Private MarkerLocation As LatLng
    Private MarkerName1, MarkerName2 As Marker

End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.SetFormStyle("UNIFIED")
    MainForm.RootPane.LoadLayout("1") 'Load the layout file.
    markerMap.Initialize
    Dim options As MapOptions
    options.StreetViewControl = False
    gmap.Initialize("gmap", options)
    Pane1.AddNode(gmap.AsPane, 0, 0, Pane1.Width, Pane1.Height)
    MainForm.Show
End Sub

Sub gmap_Ready
    btnResetMap.Enabled = True
    btnJumpToEiffel.Enabled = True

        'Set Marker1
        MarkerLocation.Initialize(10,10)
        gmap.AddMarker(10 , 10, "MarkerName1")
        MarkerName1.Position = MarkerLocation         'set Marker1's new location
        markerMap.Put(MarkerName1, 1)                 'place them both in a Map so you can retrieve Marker1's location (MarkerLocation)
       
        'Set Marker2
        MarkerLocation.Initialize(20,20)
        gmap.AddMarker(20 , 20, "MarkerName2")
        MarkerName2.Position = MarkerLocation         'set Marker2's new location
        markerMap.Put(MarkerName2, 2)                 'place them both in a Map so you can retrieve Marker1's location (MarkerLocation)    
       
End Sub

Clipboard01.jpg

Regards Roger
 

Roycefer

Well-Known Member
Licensed User
Longtime User
One does not typically directly initialize a Marker object. Rather, you call gmap.AddMarker() with all the info you want in the Marker as arguments and that method returns the created Marker, which you can then assign to a Marker variable. Example:
B4X:
Dim Marker1 as Marker = gmap.AddMarker(10 , 10, "MarkerName1")
 
Upvote 0
Top