IOS MapKit camera resets header values ​​between 6 and 354

I have MKMapView , and I'm trying to rotate the map camera title to follow the users title. I do not want to do auto tracking because it forces a zoom level that I would like to control at the same time.

The fact is that I found that the camera title will return to 0 if it comes with any value between 354 and 6 degrees. For example, when I set the camera title to 2, it will constantly bounce between 2 and 0 until I flip the phone to another title.

My solution was to simply lock it to 0 when between this range, but this is not optimal. Does anyone have any information on why this will happen? The method called when the header changes is as follows:

 - (void)setMapCameraPosition { //354,6 if (self.heading <= 6 || self.heading >= 354) { NSLog(@"****nulling heading. self.heading: %d camera.heading: %f", self.heading, self.mapView.camera.heading); self.mapView.camera.heading = 0.0f; } else { NSLog(@"changing heading. self.heading: %d camera.heading: %f", self.heading, self.mapView.camera.heading); self.mapView.camera.heading = (double)self.heading; } } 

If I don't have an if statement and just set the camera in my header, then my output ends:

 self.heading: 357 camera.heading: -0.000000 self.heading: 357 camera.heading: -0.000000 self.heading: 357 camera.heading: -0.000000 

Thus, this means that if I give a value close to the north, it will automatically return to the north in a second to make the map hopping forever.

How can I adjust the title to a degree close to the north, but not really, if the map does not delete my desired title?

+5
source share
1 answer

This problem cannot be fixed at the moment. I also ran into this problem and I'm afraid that you will need Apple technical support. Although I am afraid that the answer will be such that it is not possible at the moment, with the current SDK. In addition, the Maps application has the same behavior.

During my test, I found that binding occurs for degrees <7 and 353 . I used the slider to test the MKMapCamera header MKMapCamera in an isolated application to create a playback problem.

So, you are by far the best solution. However, I would tie not only to zero, but also to 353 and 7 degrees.

 float heading = self.heading; if( roundf( heading ) >= round( 353.0f ) && roundf( heading ) < round( 356.5f ) ) { heading = 353.0f; } else if( roundf( heading ) >= round( 356.5f ) && roundf( heading ) <= round( 360.0f ) ) { heading = 360.0f; } else if( roundf( heading ) >= round( 0.0f ) && roundf( heading ) < round( 3.5f ) ) { heading = 0.0f; } else if( roundf( heading ) >= round( 3.5f ) && roundf( heading ) <= round( 7.0f ) ) { heading = 7.0f; } [[[self mapview] camera] setHeading: heading]; 

But it is completely up to you.

+5
source

Source: https://habr.com/ru/post/1204559/


All Articles