Google Maps IOS SDK - Refreshing the MapView. (Objective-c) - ios

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.

Related

Moving Map Under the Marker in Mapbox iOS SDK

I am new in MapBox iOS SDK and I need to add a marker in the center of MGLMapView so that user would be able to move map view under the marker and the marker would be fix on the screen. I also need to get the coordinate of the point in the map that is under the marker. I could not find any method in Mapbox SDK and I have no idea how to do that.
I believe this is quite easy. Add an image of a marker on top of the map to give the visual effect so the user can still scroll around without moving the marker. Then you can get the center coordinates usually quite easily using mapView.centerCoordinate when the user stops scrolling.
Here is the API documentation link for reference
I had done something like this in one of my apps
1) Add map to UIViewController
2) Add a Transparent view on top of the map in UIViewController. (May need to set userInteractionEnabled to false. Not sure though!)
3) Add marker image to the Transparent view so that its bottom tip is at the center of the view it is added to.
4) Get center coordinates by using mapView.centerCoordinate
For other people who have this issue too:
let markerImageView = UIImageView(image: UIImage(named: "Orange"))
markerImageView.center = mapView.center
mapView.addSubview(markerImageView)

ios: disable mapView update after adding annotations and calling mapView.showAnnotations()

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];

Make a Mapbox RMAnnotation display its callout programmatically

I'm making an iOS app (using Swift) that has a map in the Mapbox iOS SDK. I've gotten to the point of displaying several markers on the map. Now, I want the user to be able to select a marker from the list, panning to that marker (easy), which also makes the marker's callout bubble appear automatically without the user having to touch it (not so easy).
It's this last task I'm having trouble with. While I've found the RMMarker class's showLabel() method, I can't seem to directly access a RMAnnotation's associated RMMarker object, so I'm not sure where or how to call this method.
Does anyone know how this is done?
Ignore the showLabel() API — this is not the callout in use, but rather a text label that's possible directly on the annotation.
You probably want -[RMMapView selectAnnotation:animated:] with a NO in the animated argument.

Customizing Mapbox Callout with HTML on iOS

I am trying to implement a custom callout using MapBox on iOS. When the user presses on the marker I would like a callout to display a UIWebView rather than a left and right accessory view and the title with text only.
I have searched through the SDK documentation and cannot find a simple way to access the view of the annotation title so I can set it to a UIWebView.
I started off by trying to access the annotation layer to see if I could make changes, such as:
RMAnnotation *annotation = [[RMAnnotation alloc] initWithMapView:mapView coordinate:CLLocationCoordinate2DMake(56.0,-4.0) andTitle:#"test"];
annotation.userInfo = #"test";
RMMapLayer *layer = annotation.layer;
layer.backgroundColor = [UIColor blackColor].CGColor;
However, when I press on the marker the annotation bubble is still white.
I have searched through the SDK to try to understand the relationship between the RMAnnotation and RMMarker classes and how they interact but think my understanding is flawed and hence I am not getting anywhere.
If anyone can help point me in the right direction that would be appreciated!
Ok, I figured out a way to make this work. Its a little of a 'hack' but it works really well for my purposes so I thought I would share. Please comment if you have a better idea and also tell me if this is not a great way to do it.
I checked the SDK source code and the RMMapView passes the SMCalloutView object the title, subtitle and left/right accessory views. When I checked the SMCalloutView code there is the ability to provide a custom callout by passing a UIView to contentView, but the RMMapView doesn't provide for passing this. My fix was to synthesize the SMCallout (_currentCallout) so that I can access contentView from my ViewController and set contentView to a UIWebView. I chose to create a new delegate method in RMMapViewDelegate called aboutToDisplayAnnotation that provides me with the opportunity to swap in my UIWebView before the callout is drawn to the screen, but I guess a better way might have been to rewrite the selectAnnotation method in RMMapView.

Show custom and default callout views on different pins with pin clustering on map view

This is my first question, and i am new to iOS.
I am implementing pin clustering on map view , which in working fine for one type of pin but my requirement is to cluster different kind of pins with different cluster count on it when zoomed out i.e if one kind of pin shows river details on map view than these pins should cluster together and give a count on it and on other case if other pin is showing details for diversion on map view than these pins should cluster together separately from river pin and give a separate count on it. and this same case is followed for other 4 different kinds of pins.
And i have one more issue , how to implement different callout views for these above different kind of pins on same map view i.e suppose river pin have default callout which includes title,subtitle and accessory button. And on other side for Diversion pin i have my own custom call out view . So now i want is when i tap on river pin than default callout should pop out and when i tap on diversion pin than my own custom callout should pop out.And same for other kind of pins too.
Please help me out . I am working on these issues from last 2 weeks but nothing working out for me. Please help me out i want a solution for these problems badly.
NOTE: The custom callout and default callout should be implemented with pin clustering.
I have created a demo, which will solve your problem about custom call out and default call out.
Answer
will guide you how to create custom call out and add pins for it.
This code contains PinAnnotation which is a subclass of MKAnnotation and acts to show custom call out.
For the default call out view you just have to add MKAnnotation to map and it will show default one.
How ever you can customise it if you want and create another sub class for it.
To test default call out with custom call out view. Download demo project from that answer link or directly from here.
Add below code at the end of viewDidLoad() and run the application.
MKPointAnnotation *pin = [[MKPointAnnotation alloc] init];
pin.coordinate = CLLocationCoordinate2DMake(34.65515f, 133.81951f);
pin.title = #"Default Pin";
[self.mapView addAnnotation:pin];
It will be looks like below:

Resources