How to delay callout from showing when annotation selected in MKMapView? Swift 4





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















(This is my first stack overflow question haha)



UPDATE:
From this link - Center MKMapView BEFORE displaying callout



I implemented the solution from Thermometer, however selecting and deselecting the annotation makes it look like my application is glitching.



I think the best way would be to delay the callOut (detail pop up) from appearing by a few seconds so the map has time to move first.



Here is my code:



func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
guard let annotation = view.annotation else {
return
}

let currentAnnotation = view.annotation as? MapMarker
Global.currentAnnotation = currentAnnotation
findRelatinoshipLines()

if Global.showLifeStoryLines {
var locations = lifeStoryAnnotations.map { $0.coordinate }
let polyline = MKPolyline(coordinates: &locations, count: locations.count)
Global.finalLineColor = Global.lifeStoryColor
mapView.addOverlay(polyline)
}

if Global.showFatherLines {
var fatherLocations = fatherTreeAnnotations.map { $0.coordinate }
let fatherPolyline = MKPolyline(coordinates: &fatherLocations, count: fatherLocations.count)
Global.finalLineColor = Global.fatherLineageColor

mapView.addOverlay(fatherPolyline)
}

if Global.showMotherLines {
var motherLocations = motherTreeAnnotations.map { $0.coordinate }
let motherPolyline = MKPolyline(coordinates: &motherLocations, count: motherLocations.count)
Global.finalLineColor = Global.motherLineageColor

mapView.addOverlay(motherPolyline)
}

if Global.showSpouseLines {
var locations = spouseAnnotations.map { $0.coordinate }
let polyline = MKPolyline(coordinates: &locations, count: locations.count)
Global.finalLineColor = Global.spouseColor
mapView.addOverlay(polyline)
}

if Global.zoomChange == true {
Global.zoomChange = false
} else {
let currentRegion = mapView.region
let span = currentRegion.span
let location = currentAnnotation!.coordinate
let region = MKCoordinateRegion(center: location, span: span)

DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
mapView.setCenter(annotation.coordinate, animated: true)
//mapView.setRegion(region, animated: true)
}
}
}


CONTINUED:



Basically I'm working on a family genealogy application that displays events from relatives on a map.



When I click an annotation (event) the details (who event belongs to, where and when, etc) pops up above with an information button to show the selected person.



I have it set up to set the MKMapView region so that the selected annotation is centered each time a new annotation is clicked.



The problem is when I click an event that is on the edge of the screen, my annotation title/description pops up off centered so that it fits on my screen because it doesn't know that I plan on re-centering the map view around said annotation.



I was wondering if there was any way to make the title/description appear centered directly above the selected annotation so that when I move the map everything is centered and fits on the screen.



Here are some screenshots of what I'm talking about:



Before and After










share|improve this question

























  • Will help if you show the code that is relevant to the issue.

    – MwcsMac
    Nov 27 '18 at 1:35











  • You should center the map before details pops up.

    – Kosuke Ogawa
    Nov 27 '18 at 2:03











  • @KosukeOgawa Yes I'm looking into doing that now with the help of this link: stackoverflow.com/questions/34397934/…

    – Hunter
    Nov 27 '18 at 2:06













  • @KosukeOgawa I implemented the solution from Thermometer on that link, however selecting and deselecting the annotation makes it look like my application is glitching. Do you have any other way of delaying the showCallout (details pop up)?

    – Hunter
    Nov 27 '18 at 5:12











  • @MwcsMac updated. Thank you!

    – Hunter
    Nov 27 '18 at 21:48


















0















(This is my first stack overflow question haha)



UPDATE:
From this link - Center MKMapView BEFORE displaying callout



I implemented the solution from Thermometer, however selecting and deselecting the annotation makes it look like my application is glitching.



I think the best way would be to delay the callOut (detail pop up) from appearing by a few seconds so the map has time to move first.



Here is my code:



func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
guard let annotation = view.annotation else {
return
}

let currentAnnotation = view.annotation as? MapMarker
Global.currentAnnotation = currentAnnotation
findRelatinoshipLines()

if Global.showLifeStoryLines {
var locations = lifeStoryAnnotations.map { $0.coordinate }
let polyline = MKPolyline(coordinates: &locations, count: locations.count)
Global.finalLineColor = Global.lifeStoryColor
mapView.addOverlay(polyline)
}

if Global.showFatherLines {
var fatherLocations = fatherTreeAnnotations.map { $0.coordinate }
let fatherPolyline = MKPolyline(coordinates: &fatherLocations, count: fatherLocations.count)
Global.finalLineColor = Global.fatherLineageColor

mapView.addOverlay(fatherPolyline)
}

if Global.showMotherLines {
var motherLocations = motherTreeAnnotations.map { $0.coordinate }
let motherPolyline = MKPolyline(coordinates: &motherLocations, count: motherLocations.count)
Global.finalLineColor = Global.motherLineageColor

mapView.addOverlay(motherPolyline)
}

if Global.showSpouseLines {
var locations = spouseAnnotations.map { $0.coordinate }
let polyline = MKPolyline(coordinates: &locations, count: locations.count)
Global.finalLineColor = Global.spouseColor
mapView.addOverlay(polyline)
}

if Global.zoomChange == true {
Global.zoomChange = false
} else {
let currentRegion = mapView.region
let span = currentRegion.span
let location = currentAnnotation!.coordinate
let region = MKCoordinateRegion(center: location, span: span)

DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
mapView.setCenter(annotation.coordinate, animated: true)
//mapView.setRegion(region, animated: true)
}
}
}


CONTINUED:



Basically I'm working on a family genealogy application that displays events from relatives on a map.



When I click an annotation (event) the details (who event belongs to, where and when, etc) pops up above with an information button to show the selected person.



I have it set up to set the MKMapView region so that the selected annotation is centered each time a new annotation is clicked.



The problem is when I click an event that is on the edge of the screen, my annotation title/description pops up off centered so that it fits on my screen because it doesn't know that I plan on re-centering the map view around said annotation.



I was wondering if there was any way to make the title/description appear centered directly above the selected annotation so that when I move the map everything is centered and fits on the screen.



Here are some screenshots of what I'm talking about:



Before and After










share|improve this question

























  • Will help if you show the code that is relevant to the issue.

    – MwcsMac
    Nov 27 '18 at 1:35











  • You should center the map before details pops up.

    – Kosuke Ogawa
    Nov 27 '18 at 2:03











  • @KosukeOgawa Yes I'm looking into doing that now with the help of this link: stackoverflow.com/questions/34397934/…

    – Hunter
    Nov 27 '18 at 2:06













  • @KosukeOgawa I implemented the solution from Thermometer on that link, however selecting and deselecting the annotation makes it look like my application is glitching. Do you have any other way of delaying the showCallout (details pop up)?

    – Hunter
    Nov 27 '18 at 5:12











  • @MwcsMac updated. Thank you!

    – Hunter
    Nov 27 '18 at 21:48














0












0








0


1






(This is my first stack overflow question haha)



UPDATE:
From this link - Center MKMapView BEFORE displaying callout



I implemented the solution from Thermometer, however selecting and deselecting the annotation makes it look like my application is glitching.



I think the best way would be to delay the callOut (detail pop up) from appearing by a few seconds so the map has time to move first.



Here is my code:



func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
guard let annotation = view.annotation else {
return
}

let currentAnnotation = view.annotation as? MapMarker
Global.currentAnnotation = currentAnnotation
findRelatinoshipLines()

if Global.showLifeStoryLines {
var locations = lifeStoryAnnotations.map { $0.coordinate }
let polyline = MKPolyline(coordinates: &locations, count: locations.count)
Global.finalLineColor = Global.lifeStoryColor
mapView.addOverlay(polyline)
}

if Global.showFatherLines {
var fatherLocations = fatherTreeAnnotations.map { $0.coordinate }
let fatherPolyline = MKPolyline(coordinates: &fatherLocations, count: fatherLocations.count)
Global.finalLineColor = Global.fatherLineageColor

mapView.addOverlay(fatherPolyline)
}

if Global.showMotherLines {
var motherLocations = motherTreeAnnotations.map { $0.coordinate }
let motherPolyline = MKPolyline(coordinates: &motherLocations, count: motherLocations.count)
Global.finalLineColor = Global.motherLineageColor

mapView.addOverlay(motherPolyline)
}

if Global.showSpouseLines {
var locations = spouseAnnotations.map { $0.coordinate }
let polyline = MKPolyline(coordinates: &locations, count: locations.count)
Global.finalLineColor = Global.spouseColor
mapView.addOverlay(polyline)
}

if Global.zoomChange == true {
Global.zoomChange = false
} else {
let currentRegion = mapView.region
let span = currentRegion.span
let location = currentAnnotation!.coordinate
let region = MKCoordinateRegion(center: location, span: span)

DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
mapView.setCenter(annotation.coordinate, animated: true)
//mapView.setRegion(region, animated: true)
}
}
}


CONTINUED:



Basically I'm working on a family genealogy application that displays events from relatives on a map.



When I click an annotation (event) the details (who event belongs to, where and when, etc) pops up above with an information button to show the selected person.



I have it set up to set the MKMapView region so that the selected annotation is centered each time a new annotation is clicked.



The problem is when I click an event that is on the edge of the screen, my annotation title/description pops up off centered so that it fits on my screen because it doesn't know that I plan on re-centering the map view around said annotation.



I was wondering if there was any way to make the title/description appear centered directly above the selected annotation so that when I move the map everything is centered and fits on the screen.



Here are some screenshots of what I'm talking about:



Before and After










share|improve this question
















(This is my first stack overflow question haha)



UPDATE:
From this link - Center MKMapView BEFORE displaying callout



I implemented the solution from Thermometer, however selecting and deselecting the annotation makes it look like my application is glitching.



I think the best way would be to delay the callOut (detail pop up) from appearing by a few seconds so the map has time to move first.



Here is my code:



func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
guard let annotation = view.annotation else {
return
}

let currentAnnotation = view.annotation as? MapMarker
Global.currentAnnotation = currentAnnotation
findRelatinoshipLines()

if Global.showLifeStoryLines {
var locations = lifeStoryAnnotations.map { $0.coordinate }
let polyline = MKPolyline(coordinates: &locations, count: locations.count)
Global.finalLineColor = Global.lifeStoryColor
mapView.addOverlay(polyline)
}

if Global.showFatherLines {
var fatherLocations = fatherTreeAnnotations.map { $0.coordinate }
let fatherPolyline = MKPolyline(coordinates: &fatherLocations, count: fatherLocations.count)
Global.finalLineColor = Global.fatherLineageColor

mapView.addOverlay(fatherPolyline)
}

if Global.showMotherLines {
var motherLocations = motherTreeAnnotations.map { $0.coordinate }
let motherPolyline = MKPolyline(coordinates: &motherLocations, count: motherLocations.count)
Global.finalLineColor = Global.motherLineageColor

mapView.addOverlay(motherPolyline)
}

if Global.showSpouseLines {
var locations = spouseAnnotations.map { $0.coordinate }
let polyline = MKPolyline(coordinates: &locations, count: locations.count)
Global.finalLineColor = Global.spouseColor
mapView.addOverlay(polyline)
}

if Global.zoomChange == true {
Global.zoomChange = false
} else {
let currentRegion = mapView.region
let span = currentRegion.span
let location = currentAnnotation!.coordinate
let region = MKCoordinateRegion(center: location, span: span)

DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
mapView.setCenter(annotation.coordinate, animated: true)
//mapView.setRegion(region, animated: true)
}
}
}


CONTINUED:



Basically I'm working on a family genealogy application that displays events from relatives on a map.



When I click an annotation (event) the details (who event belongs to, where and when, etc) pops up above with an information button to show the selected person.



I have it set up to set the MKMapView region so that the selected annotation is centered each time a new annotation is clicked.



The problem is when I click an event that is on the edge of the screen, my annotation title/description pops up off centered so that it fits on my screen because it doesn't know that I plan on re-centering the map view around said annotation.



I was wondering if there was any way to make the title/description appear centered directly above the selected annotation so that when I move the map everything is centered and fits on the screen.



Here are some screenshots of what I'm talking about:



Before and After







swift annotations mkmapview callouts






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 27 '18 at 17:52







Hunter

















asked Nov 27 '18 at 1:19









HunterHunter

33




33













  • Will help if you show the code that is relevant to the issue.

    – MwcsMac
    Nov 27 '18 at 1:35











  • You should center the map before details pops up.

    – Kosuke Ogawa
    Nov 27 '18 at 2:03











  • @KosukeOgawa Yes I'm looking into doing that now with the help of this link: stackoverflow.com/questions/34397934/…

    – Hunter
    Nov 27 '18 at 2:06













  • @KosukeOgawa I implemented the solution from Thermometer on that link, however selecting and deselecting the annotation makes it look like my application is glitching. Do you have any other way of delaying the showCallout (details pop up)?

    – Hunter
    Nov 27 '18 at 5:12











  • @MwcsMac updated. Thank you!

    – Hunter
    Nov 27 '18 at 21:48



















  • Will help if you show the code that is relevant to the issue.

    – MwcsMac
    Nov 27 '18 at 1:35











  • You should center the map before details pops up.

    – Kosuke Ogawa
    Nov 27 '18 at 2:03











  • @KosukeOgawa Yes I'm looking into doing that now with the help of this link: stackoverflow.com/questions/34397934/…

    – Hunter
    Nov 27 '18 at 2:06













  • @KosukeOgawa I implemented the solution from Thermometer on that link, however selecting and deselecting the annotation makes it look like my application is glitching. Do you have any other way of delaying the showCallout (details pop up)?

    – Hunter
    Nov 27 '18 at 5:12











  • @MwcsMac updated. Thank you!

    – Hunter
    Nov 27 '18 at 21:48

















Will help if you show the code that is relevant to the issue.

– MwcsMac
Nov 27 '18 at 1:35





Will help if you show the code that is relevant to the issue.

– MwcsMac
Nov 27 '18 at 1:35













You should center the map before details pops up.

– Kosuke Ogawa
Nov 27 '18 at 2:03





You should center the map before details pops up.

– Kosuke Ogawa
Nov 27 '18 at 2:03













@KosukeOgawa Yes I'm looking into doing that now with the help of this link: stackoverflow.com/questions/34397934/…

– Hunter
Nov 27 '18 at 2:06







@KosukeOgawa Yes I'm looking into doing that now with the help of this link: stackoverflow.com/questions/34397934/…

– Hunter
Nov 27 '18 at 2:06















@KosukeOgawa I implemented the solution from Thermometer on that link, however selecting and deselecting the annotation makes it look like my application is glitching. Do you have any other way of delaying the showCallout (details pop up)?

– Hunter
Nov 27 '18 at 5:12





@KosukeOgawa I implemented the solution from Thermometer on that link, however selecting and deselecting the annotation makes it look like my application is glitching. Do you have any other way of delaying the showCallout (details pop up)?

– Hunter
Nov 27 '18 at 5:12













@MwcsMac updated. Thank you!

– Hunter
Nov 27 '18 at 21:48





@MwcsMac updated. Thank you!

– Hunter
Nov 27 '18 at 21:48












1 Answer
1






active

oldest

votes


















0














Solved it by calling setCenter with a slight delay in mapView(_:didSelect:):



func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
guard let annotation = view.annotation else {
return
}

DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
mapView.setCenter(annotation.coordinate, animated: true)
}
}


enter image description here






share|improve this answer
























  • I tried this and instead of delaying the pop up - it delays the map centering. Check my post update for my code.

    – Hunter
    Nov 27 '18 at 17:43













  • Is this because my annotations are markers and not pins?

    – Hunter
    Nov 27 '18 at 21:55












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53491447%2fhow-to-delay-callout-from-showing-when-annotation-selected-in-mkmapview-swift-4%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Solved it by calling setCenter with a slight delay in mapView(_:didSelect:):



func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
guard let annotation = view.annotation else {
return
}

DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
mapView.setCenter(annotation.coordinate, animated: true)
}
}


enter image description here






share|improve this answer
























  • I tried this and instead of delaying the pop up - it delays the map centering. Check my post update for my code.

    – Hunter
    Nov 27 '18 at 17:43













  • Is this because my annotations are markers and not pins?

    – Hunter
    Nov 27 '18 at 21:55
















0














Solved it by calling setCenter with a slight delay in mapView(_:didSelect:):



func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
guard let annotation = view.annotation else {
return
}

DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
mapView.setCenter(annotation.coordinate, animated: true)
}
}


enter image description here






share|improve this answer
























  • I tried this and instead of delaying the pop up - it delays the map centering. Check my post update for my code.

    – Hunter
    Nov 27 '18 at 17:43













  • Is this because my annotations are markers and not pins?

    – Hunter
    Nov 27 '18 at 21:55














0












0








0







Solved it by calling setCenter with a slight delay in mapView(_:didSelect:):



func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
guard let annotation = view.annotation else {
return
}

DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
mapView.setCenter(annotation.coordinate, animated: true)
}
}


enter image description here






share|improve this answer













Solved it by calling setCenter with a slight delay in mapView(_:didSelect:):



func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
guard let annotation = view.annotation else {
return
}

DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
mapView.setCenter(annotation.coordinate, animated: true)
}
}


enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 27 '18 at 14:55









Kosuke OgawaKosuke Ogawa

5,55522444




5,55522444













  • I tried this and instead of delaying the pop up - it delays the map centering. Check my post update for my code.

    – Hunter
    Nov 27 '18 at 17:43













  • Is this because my annotations are markers and not pins?

    – Hunter
    Nov 27 '18 at 21:55



















  • I tried this and instead of delaying the pop up - it delays the map centering. Check my post update for my code.

    – Hunter
    Nov 27 '18 at 17:43













  • Is this because my annotations are markers and not pins?

    – Hunter
    Nov 27 '18 at 21:55

















I tried this and instead of delaying the pop up - it delays the map centering. Check my post update for my code.

– Hunter
Nov 27 '18 at 17:43







I tried this and instead of delaying the pop up - it delays the map centering. Check my post update for my code.

– Hunter
Nov 27 '18 at 17:43















Is this because my annotations are markers and not pins?

– Hunter
Nov 27 '18 at 21:55





Is this because my annotations are markers and not pins?

– Hunter
Nov 27 '18 at 21:55




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53491447%2fhow-to-delay-callout-from-showing-when-annotation-selected-in-mkmapview-swift-4%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen