I'm building an app where annotations mark points of interest that the user drives by. The map tracks the user's location and scrolls along, but annotations that should come into view on the map don't appear until the user drags the map with her finger.
Adding and removing annotations works fine so I'm not sure what code to show.
Has anyone seen similar behavior?
Edit:
This affects only some annotations - some appear, some don't. No apparent pattern.
As suggested, I've changed the code so that I add and remove annotations only on the main thread:
dispatch_async(dispatch_get_main_queue(), ^{
[self.mapView removeAnnotations:annotationsToRemove];
[self.mapView addAnnotations:annotationsToAdd];
});
But the problem persists. Darn...
For me I just had to call addAnnotations on the main thread:
dispatch_async(dispatch_get_main_queue(), ^{
[self.mapView addAnnotations:annotations];
});
And it works fine
when you add an annotation call all the following methods on that annotation for it to show.
[_mapView addAnnotation:theAnnotation];
[_mapView deselectAnnotation:theAnnotation animated:NO];
[_mapView selectAnnotation:theAnnotation animated:NO];
For some of the apps I have worked on, unless you deselect and select the annotation, it wouldn't show it on the map (even if you just add it). Hope this helps!
It's hard to say without seeing any of your code. That being said, if you haven't already, try checking to see if any of the annotations are within the current visible map area in mapView:didUpdateUserLocation and, if they are, refresh your map view (see the answer to How do you check if an MKAnnotation is available within a MKCoordinateRegion for more on checking annotations against the visible map rect).
Related
I have just build an swift app that takes data+coords from dynamoDB and puts it onto the ios mapkit. There are two sets of coords: one for current user location and one from dynamoDB. I want these coords to be able to update inside the map, but do not want the actual mapView to zoom and move at all (only the user can zoom and move).
I have achieved everything above except the last part. Currently whenever the annotations are added and mapView.showAnnotations is called, the mapView zooms and moves to enclose the annotations. How do I disable this?
To show mapView annotations without updating mapView zoom and constraints, use addAnnotations() rather than showAnnotations.
I am guessing that you used code from online (which we all do, no worries) and that your code looked something like this. If I am right, then you likely have a line somewhere like this:
[map setRegion:scaledRegion animated:YES];
That line is the issue. You need to use some sort of boolean to make it so that it only happens once. So you could set the boolean has_mapped = false until you have called your update method once, at which point it = true. Then change your line to say something like,
if (has_mapped)
[map setRegion:scaledRegion animated:YES];
I have an IOs app that adds annotations when they enter the visible map view. This works well and keeps the total pins on the map low however this also looks buggy as the annotations are only added to the map when map scrolling has finished/completed. Does anyone know a way to add pins to the map whilst it's still scrolling so that the experience is fluid?
Many thanks,
Matt
Do you add annotaion to MapView on the main thread?
ex)
dispatch_async(dispatch_get_main_queue(), {
self?.mapView.addAnnotation(venueAnnotation)
})
I made a settings tab for the MapView's ViewController and it works fine when I open the MapViews's VC the first time. but when I change the settings after I opened and loaded the mapView the first time the settings that I changed don't apply to the mapView because it did not refresh. Is there a way of refreshing the data of the mapView? I have searched everywhere and couldn't find an answer.
if this question have been answerd before can you link me to it? Thank you.
I'm using the GoogleMaps ios sdk.
and I'm using obj-c.
If your settings just changes the icons, annotations, map markers or layers color , or location of markers or layer, the simplest way to do is clear all the markers and layers you add on the map view and re-add them. For example, implement a refreshMapView method
-(void)refreshMapView
{
[mapView clear];//this line clears all the markers or layers you drew on the mapView.
// then implement your method to re-draw the markers and layers, or load new settings.
// for example, go through your marker list, and add them as follows:
for (id yourobject in yourMarkerArray){
GMSMarker *marker = [GMSMarker markerWithPosition:coordinatesOfMarker];
//custom marker here, set title, or snippets, or icon, etc...
marker.map = mapView;
}
// you can also redraw any map overlay here...
}
Jing's answer to implement a refreshMapView method is good, you could call that in your map view controller's viewWillAppear section.
Make sure you're actually setting the mapView properties in the same scope — i.e., your settings view and your map view may be looking at a different object or changes may be getting discarded. Without seeing the code for how you're trying to modify those settings, it's difficult to say.
I would like to know how I can make sure that a callout bubble can't get deselected on a MKMapView.
Whenever I press on the map (background), this view:
Turns to:
Which I do not want to allow. Yet I do want to keep the callOutButton support.
You could just programmatically select your annotation whenever annotations get deselected (using the corresponding delegate method). If you don't animate this selection then it looks as if the annotation never got deselected in the first place.
Example:
// MKMapView Delegate
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view {
// Replace "myAnnotation" with whichever annotation you need to remain selected
[mapView selectAnnotation:self.myAnnotation animated:NO];
}
I tried this in a test project and it works fine (it doesn't flicker or anything). It's not exactly disabling deselection but the resulting effect is the same, so it might be a good workaround.
I'm working on an app that shows a couple of places on the map along with the user's current position.
I have two small problems with it:
First off, I want the current location pin to be the default blue circle, but it shows a green pin just like the other locations.
Second problem, whenever I touch the screen, the current location pin drops again. It just can't seem to be steady like the other ones. It's like it's being called whenever I interact with the app.
Make sure you set your mapView delegate to self...that should fix the pin color. Not sure about your other problem
// in the viewDidLoad
[mapView setDelegate:self];
where "mapView" is defined as "IBOutlet MKMapView *mapView;"