MapBox marker offset

元气小坏坏 提交于 2020-01-06 08:16:20

问题


I'm using the MapBox SDK for iOS and encountered a problem I can't find a good solution for. In the iOS the MKAnnotationView allows me to do the following:

        view.centerOffset = CGPointMake(0, -15);

Is there a MapBox RMMarker equivalent for this?

So basically I need to move the marker a few pixels up from its original position, taking the zoom level into account as well. (So when you zoom, the marker's bottom part keeps fixed on the same point)

As you can guess, there's a little arrow at the bottom of my marker that I want to have pointing to the GPS position in question, but the RMMarker seems to center on this point right now rather than being positioned on top of it, like I'd need.


回答1:


On mapbox it's proportional bwn 0 - 1.0;

So if we want it centered it would be

CGPointMake(0.5, 0.5);

Use this:

- (id)initWithUIImage:(UIImage *)image anchorPoint:(CGPoint)anchorPoint

RMMarker * marker = [RMMarker initWithUIImage:[UIImage imageNamed:@"yourImage.png"] anchorPoint:CGPoint(0.5,1.0)];   

If you want the bottom of the image to point to the location, I think you'd want either 1.0 or -1.0 as your Y point. I don't have a MapBox proj available right here to test it.

See Docs Here



来源:https://stackoverflow.com/questions/22561998/mapbox-marker-offset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!