-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MapAnnotations not centered properly #14
Comments
I'm not entirely sure why this is. I have experienced minor issues in this regard, but this seems to be off pretty much for all of the annotations and not even in the same direction, right? Could you maybe provide a minimal example project experiencing this issue, so that I could debug this? Would be greatly appreciated. |
This is even stranger actually because sometimes when the app stars, this is ok, and and once when swapping maps back and forth, it becomes twisted with no change to the underlying data... |
It's quite hard to predictably reproduce this issue for me - but I have a promising idea. Could you please try #18 whether it fixes that behavior? |
I just tried the most recent change on that branch and it worked without the issue appearing at all - if you notice this issue persists in future versions of Map, please let me know that this still persists/reappeared! Closing this for now - will reopen, if the issue persists. |
Reopening, since it doesn't seem to be fully solved. I was still able to reproduce this issue in certain cases. Not really sure what the issue here is - seems to be somewhat related to safe area insets, maybe? |
Can also confirm that the last commit does not solve this issue. |
I've created a stripped down test project where I can reproduce the problem. How can I send it to you @pauljohanneskraft ? |
Thank you very much! You can send it as a zip right here by drag-and-dropping it in the text field, if you want. |
Here you go @pauljohanneskraft . You'll see that the white dots are not properly centered on the track (that could be me not setting them correctly), but they also rotate around a center slightly outside of them when you rotate the view for example. This offset is not constant from one app start to another... |
Thank you very much! 😊 |
I've also been experiencing this issue, but it doesn't happen for all annotations. During the same run, some will be placed correctly, and some will be off. Creating a minimal example isn't going to be possible for me, but I'm down to try things. |
@alex-reilly-pronto Thank you very much! So what I have already figured out in the example above is, that the backwards support for In addition to that, there seems to be an issue with ignoring the safe area - I will have a look at that as well. It seemingly only appears once the first one is "fixed". If you do not ignore the safe area for now, they should be at the place where they belong (which is ofc not a satisfactory solution, I know). |
Is this maybe because MapAnnotation(coordinate: coordinate, anchorPoint: .init(x: 0.5, y: 1.0)) {
MyPinView()
}
|
@eugenijusr It is right that the @alex-reilly-pronto and @rderimay It would be really nice, if you could try to put |
@pauljohanneskraft I changed MKAnnotation to a As for the |
We developed a similar library to yours. We also placed the view for the annotation into a This was solved by using the We did not fix this fully and finish the library ourselves but maybe this info could help you somehow. |
I'm experiencing the same issue, only when the |
Have folks been able to predictably reproduce the bug? Could the annotation be manually offset to counteract it? |
I can reproduce consistently with the following piece of code (as we zoom out, the circle shows up out of their coordinate center - the SwiftUI's Map is working fine in this scenario, in fact using a MKMarkerAnnotationView also works fine):
One note:
|
Updating the MKMapAnnotationView's setup method to this, has an interesting effect:
^ The black square is the controller's view and it has the right position (no matter if you zoom in or out), but for some reason the content (SwiftUI View) is misplaced. |
I think I found a solution, appliying this two changes on the MKMapAnnotationView make it work:
^ This help to keep the annotation view position. But in my case, my SwiftUI's view has a pulse effect (and the ring circles are misplaced, for some reason those circles didn't reposition) |
This completely breaks the subviews of your custom View that you pass in the |
In the end, the changes that are working for me (including the animation on SwiftUI content) are this:
|
@Abreu0101 Thanks for this! I had to add the top and bottom constraints as well to make it work for my use case but then it worked all fine 👍
|
@Abreu0101 I take back what I wrote above. Your code made it better but did not solve the issue entirely for me. Upon investigating a bit closer I found out that the You need to disable the SafeArea behaviour for the
|
@BucekJiri Thanks for sharing that article, that explain a lot of things. 👏🏼 |
@BucekJiri Your patch looks like it's working for me :) Thanks! |
Btw you could just do |
@BucekJiri I can not get where to put you updateContent function in my SwiftUI view to make it working. If you could explain, it would be very nice. Thanks ! |
@rderimay You can check the PR for annotation selection where you can see how this is used in the |
@BucekJiri Thanks! I saw this but as there is no PR for the centring fix, I was a bit unsure how to integrate that in the code actually. I will probably make a fork to integrate it in my code quickly unless there is a better solution... |
I'm experiencing the same thing. My assumption is that the circle in your screenshot is indeed centered, but centered inside the safe area, while the map view extends outside of it. |
Not sure if the problem comes from your package or from MapKit directly. Whenever I add MapAnnotations, these are not centered on their middle point and rotate around another near point when rotating the map
The crazy thing is that this does not always happen. Rarely, after the app being compiled, it works perfectly...
The text was updated successfully, but these errors were encountered: