MarkerViewManager setOffset not right for Marker
Hi Mapbox Team.
I'm Using SDK 4.0.1 beta 2
However I have a problem with markers location in map.
When i'm use MarkerOptions for create Marker.
--> Position of marker always right with LatLng in MapView with offsetX, Y
But when, i'm use MarkerViewOptions for create Marker
--> Position of marker not right with LatLng in MapView with offsetX, Y.
When i zoom in, or zoom out. offsetX, Y of markers changing and not true for LatLng
I'm found that problem not right from method update from com.mapbox.mapboxsdk.annotations.MarkerViewManager class.
public void update() {
View convertView;
for (MarkerView marker : markerViewMap.keySet()) {
convertView = markerViewMap.get(marker);
if (convertView != null) {
PointF point = mapboxMap.getProjection().toScreenLocation(marker.getPosition());
int x = (int) (marker.getAnchorU() * convertView.getMeasuredWidth());
int y = (int) (marker.getAnchorV() * convertView.getMeasuredHeight());
marker.setOffsetX(x);
marker.setOffsetY(y);
convertView.setX(point.x - x);
convertView.setY(point.y - y);
if (marker.isVisible() && convertView.getVisibility() == View.GONE) {
convertView.animate().cancel();
convertView.setAlpha(0);
AnimatorUtils.alpha(convertView, 1);
}
}
}
}
If now i can Custom or change MarkerViewManager for MapboxMap, Who know it, share for me, please!
Marker in road

Marker move to lake when zoom out
If Zoom out to zoom small level, LatLng position move to out that region!
And If that's can't, Support me when u fix it! Thanks so much!
@Buminta
those methods are for internal use only: note that the visibility of the methods are limited to package visibility and not public.
/**
* Internal method to set the horizontal calculated offset.
* <p>
* These are calculated based on the View bounds and the provided anchor.
* </p>
*
* @param x the x-value of the offset
*/
void setOffsetX(float x) {
offsetX = x;
}
/**
* Internal method to set the vertical calculated offset.
* <p>
* These are calculated based on the View bounds and the provided anchor.
* </p>
*
* @param y the y-value of the offset
*/
void setOffsetY(float y) {
offsetY = y;
}
to alter the position placement of a MarkerView please use anchoring instead:
/**
* Specifies the anchor being set on a particular point point of the MarkerView.
* <p>
* The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0], where (0, 0)
* is the top-left corner of the image, and (1, 1) is the bottom-right corner.
* </p>
*
* @param u u-coordinate of the anchor, as a ratio of the image width (in the range [0, 1])
* @param v v-coordinate of the anchor, as a ratio of the image height (in the range [0, 1])
*/
public void setAnchor(@FloatRange(from = 0.0, to = 1.0) float u, @FloatRange(from = 0.0, to = 1.0) float v) {
this.anchorU = u;
this.anchorV = v;
}
Reach out if you have any other questions.
@Buminta 我们还是来点中文吧,这个问题您那边是怎么解决的?
@tobrun int x = (int) (marker.getAnchorU() * convertView.getMeasuredWidth()); convertView.getMeasuredWidth()
Get the value has been 0, I would like to ask how to deal with, thank you!
@shiyuankao
Hey u.
Because i don't know how to make it.
However in now. I'm using method setAnchor(0.5, 0.5) for my icon with Class extend from MarkerView.
It's right!
U, V value is position origin from icon drawer (image, view,...) of u. Something like transition-origin with CSS3.
@shiyuankao we resolved this issue in https://github.com/mapbox/mapbox-gl-native/issues/5513 and should be available in our SNAPSHOT to work around this issue.