Search code examples
iosswiftmapscartodbcarto-mobile

How to rotate location marker in ios using carto-mobile( CARTO-SDK)


I am using Carto-Mobile and I am trying to rotate the location marker using CLLocation true hedding, but I can't make it work.

I set a bitmap image to the location marker which is a NTPoint object, but NTPoint doesn't have any method to rotate according to the angle, instead of NTMarker, I try to use a NTMarker for location marker but at low zoom levels (zoom 6) never show the real position so NTPoint was a better fit.

So I hope anyone can tell me how I could rotate the location marker using CLLocation true hedding using CARTO-SDK

Regards


Solution

  • Following code should work and keep image in precise location:

        NTMarkerStyleBuilder *builder = [[NTMarkerStyleBuilder alloc]init];
    
        // anchor 0,0 means that image is rotated from the center
        // you may have different anchor point depending on graphics
        [builder setAnchorPointX:0 anchorPointY:0];
    
        self.positionMarker = [[NTMarker alloc] initWithPos:position style:[builder buildStyle]];
    
       ...
       // rotate marker, depending on marker graphics
       // "180-course" is ok if it is "arrow down"
       // additional adjustment is for mapView rotation, image keeps
       // here correct course even if map is rotated
    
      double course = location.course;
      [self.positionMarker setRotation: 180 - course - self.contentView.mapView.getRotation];