B4J Question Google Maps Waypoint Anchor Change

RichardN

Well-Known Member
Licensed User
Longtime User
Any marker added with the jGoogleMaps library displays the marker with the bitmap anchored at the centre of the bottom margin. Is it possible to expose the properties of the marker such that the bitmap is centred over the co-ordinate rather than above it?

Rather like the Android library GoogleMapExtras MarkerObject.Anchor(xOffset,yOffset) provides? Can this be exposed with a JavaObject?
 

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
try this from @warwound


There is a Markerextras class which will allow you to set the anchor for the marker.

B4X:
    Private mrke As MarkerExtras
    mrke.SetAnchor(mrk,xoff,yoff)

xoff and yoff are between 0 and 1, so

B4X:
    mrke.SetAnchor(mrk,0.5,0.5)

set the anchor to the middle of the marker.
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
Andrew.... I believe you are referring to @warwound's excellent library for B4A.

I don't believe that library functions with B4J
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1606113596659.png


B4X:
Dim m As Marker = gmap.AddMarker(30, 30, "test")
Dim jo As JavaObject = m
Log(jo.GetFieldJO("jsObject").RunMethod("eval", Array($"
 var image = {
    url: 'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png',
    size: new google.maps.Size(20, 32),
    origin: new google.maps.Point(0, 0),
    anchor: new google.maps.Point(0, 32)
    };

    this.setIcon(image);
"$)))
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
I have learnt several lessons in dealing with Google Maps Marker Objects.......

1. The default marker anchor is not at all intuitive. If you are hoping to add a polyline depicting a route, having the line pass through the bottom-centre of the marker is not visually pleasing. The only exception to this is perhaps a triangle graphic with the apex pointing downwards.

2. If you centre the anchor make sure your marker graphic has a sufficiently clear area at the centre, or use transparency, so that you can actually see the anchor position when you drag it.

3. For the uninitiated.... Java Object code is difficult to write and almost impossible to debug if it does not work because there is little feedback. For this reason I have put a known working example into a class module and call it from there supplying suitable constants for various alignments. Acknowledgements to @Erel and @Andrew (Digitwell) for some snippets of the code.
 

Attachments

  • jMarker Example.zip
    10.2 KB · Views: 214
  • jCustomMarker.bas
    1.5 KB · Views: 197
Upvote 0
Top