Android Question How to load an image as marker in Google Map

AndroidMadhu

Active Member
Licensed User
Hello,
I want to load a self made .png at google map as a marker.
Can anyone advice as how to load the self made [.png] marker in google map.
Sudo code snippet will be helpful.

Thanks.
 

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
try using AddMarker3 on the GoogleMap object.

I pulled these lines from a working app,
marker is a list of map objects which contains 4 values, latitude, longitude,name and imagefilename.
gmap is the GoogleMap object
e.g.
B4X:
    For Each mrk as map  In markers.values
        Private mapmrk As Marker = gmap.AddMarker3(mrk.Get("latitude"),mrk.Get("longitude"),mrk.getdefault("name","Title"),LoadBitmapResize(File.DirAssets,mrk.getdefault("image","defaultimage.png"),30dip,30dip,True)) 'ignore
   Next

Also take a look at this link https://www.b4x.com/android/forum/threads/addmarker3-bitmapsize-and-google-maps.30378/#content
 
Upvote 0

AndroidMadhu

Active Member
Licensed User
I am getting error while running the above code..

B4X:
Sub Activity_Create(FirstTime As Boolean)

Activity.LoadLayout("1") 'layout basic template
Wait For MapFragment1_Ready
gmap = MapFragment1.GetMap
rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result Then

Log(Tracker.gpslat)
Log(Tracker.gpslong)

gmap.MyLocationEnabled = True
gmap.TrafficEnabled=True
'gmap.MyLocation.Initialize(Tracker.gpslat,Tracker.gpslong)

Do While gmap.MyLocation.IsInitialized = False
Log("Location not initialized... Sleep a while...")
Sleep(250)
Loop
If gmap.MyLocation.IsInitialized Then
Dim CameraPosition1 As CameraPosition 'CameraPosition1.Initialize2(gmap.MyLocation.Latitude, gmap.MyLocation.Longitude, gmap.CameraPosition.Zoom, 0, 0)
gmap.MapType=gmap.MAP_TYPE_NORMAL

CameraPosition1.Initialize(gmap.MyLocation.Latitude,gmap.MyLocation.Longitude, 16)
gmap.AnimateCamera(CameraPosition1)

Sleep(2000)
CameraPosition1.Initialize(gmap.MyLocation.Latitude,gmap.MyLocation.Longitude, 18)
gmap.AnimateCamera(CameraPosition1)



For Each mrk As Map   In markers.values <---- here I am getting error as "marker not defined"
Private mapmrk As Marker = gmap.AddMarker3(mrk.Get("latitude"),mrk.Get("longitude"),mrk.getdefault("name","Title"),LoadBitmapResize(File.DirAssets,mrk.getdefault("image","defaultimage.png"),30dip,30dip,True)) 'ignore
Next



End If

Else
Log("No permission!")
End If
End Sub

Also I hv put the marker[.png] at the below location

D:\MyGmap\Android-B4A\MyLocation\Objects\res\drawable
 
Upvote 0
Top