custom frame to annotation view mapbox not working - ios

Im using mapbox and adding a custom annotation view to it. But somehow the annotation view's height is not reflecting.
Here's the code for it.
- (void)viewDidLoad {
[super viewDidLoad];
MGLMapView *mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds];
mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
MGLPointAnnotation *point = [[MGLPointAnnotation alloc] init];
point.coordinate = CLLocationCoordinate2DMake(38.894368, -77.036487);
point.title = #"Hello world!";
point.subtitle = #"Welcome to The Ellipse.";
mapView.delegate = self;
[mapView setCenterCoordinate:point.coordinate zoomLevel:12 animated:NO];
[mapView addAnnotation:point];
[self.view addSubview:mapView];
// Do any additional setup after loading the view, typically from a nib.
}
-(UIView *)mapView:(MGLMapView *)mapView leftCalloutAccessoryViewForAnnotation:(id<MGLAnnotation>)annotation
{
customAnnotationView *view = [[[NSBundle mainBundle] loadNibNamed:#"customAnnotationView" owner:self options:nil] objectAtIndex:0];
[view setFrame:CGRectMake(0, 0, 260, 100)];
return view;
}
Here the height of view is not reflecting on map.

SMCalloutView, which the Mapbox iOS SDK uses to provide annotation callouts, doesn't dynamically resize based on its child views' height. (At least, it doesn't with how Mapbox configures SMCalloutView by default).
More callout view customization is coming with v3.1.0, though!
mapView:calloutViewForAnnotation: and MGLCalloutView will allow you to completely customize the appearance.

Related

How to remove the Blue and gray annotions of mapbox in iOS

How Can I Remove the user location icon defaultly shown by the map box
- (MGLAnnotationView *)mapView:(MGLMapView *)mapView viewForAnnotation:(id<MGLAnnotation>)annotation{
if (mapView.userTrackingMode == MGLUserTrackingModeFollow) {
return nil;
}
return Nil;
}
Hi, I have implemented this code.And I viewdidloadTried this
mapView.tintColor = [UIColor clearColor];
mapView.backgroundColor = [UIColor clearColor];
[mapView.attributionButton setTintColor:[UIColor clearColor]];
But still Showing ...
Mapbox documentation
you have configured your application’s location permissions, display the device’s current location on the map by setting the showsUserLocation property on the map view to NO
- (void)viewDidLoad {
[super viewDidLoad];
MGLMapView *mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds];
mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[mapView setCenterCoordinate:CLLocationCoordinate2DMake(40.74699, -73.98742)
zoomLevel:9
animated:NO];
[self.view addSubview:mapView];
mapView.styleURL = [MGLStyle satelliteStreetsStyleURL];
// Add a point annotation
MGLPointAnnotation *annotation = [[MGLPointAnnotation alloc] init];
annotation.coordinate = CLLocationCoordinate2DMake(40.77014, -73.97480);
annotation.title = #"Central Park";
annotation.subtitle = #"The best park in New York City!";
[mapView addAnnotation:annotation];
// Set the map view's delegate
mapView.delegate = self;
// Allow the map view to display the user's location
mapView.showsUserLocation = NO;
}
If you check the documentation, you'll find that mapView.showsUserLocation = false should do the trick.

how to show custom map in MapBox IOS sdk

I am new in MapBox IOS sdk and i have no idea,how to load custom Map in MapBox.
Here my Custom Map:
https://api.tiles.mapbox.com/v4/faridullah.loj1n5f3/page.html?access_token=pk.eyJ1IjoiZmFyaWR1bGxhaCIsImEiOiJVU3ZCNS1VIn0.Owqu7VB5OZQbGj3LBBpPOA#16/33.6471/72.9881
and my code:
#define kMapboxMapID #"faridullah.loj1n5f3"
- (void)viewDidLoad {
[super viewDidLoad];
RMMapboxSource *onlineSource = [[RMMapboxSource alloc] initWithMapID:kMapboxMapID];
RMMapView *mapView = [[RMMapView alloc] initWithFrame:self.view.bounds andTilesource:onlineSource];
mapView.zoom = 5;
mapView.delegate = self;
mapView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.view addSubview:mapView];
mapView.showsUserLocation=YES;
}
but the markers doesnot display on device...
Just follow this example and implement the needed or delegate methods
https://www.mapbox.com/mapbox-ios-sdk/examples/marker-custom-image/

How to make custom UIView OR label on GMSMarker Google

I have to add a custom label on Marker pin of Google maps in IOS.
I have already implemented markerInfoWindow method. But it works after i tapped on marker/Pin.
I need to show custom label at start as long as mapview will load on view without performing any action. As we can set icon or title on the marker, I need to show my own Custom view on it.
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {
CLLocationCoordinate2D anchor = marker.position;
// CGPoint point = [mapView.projection pointForCoordinate:anchor];
// self.calloutView.title = marker.title;
[self.calloutView setFrame:CGRectMake(0, 50, 25, 25)];
self.calloutView.layer.cornerRadius = 11.0;
self.calloutView.layer.masksToBounds = YES;
self.calloutView.layer.borderColor = [UIColor clearColor].CGColor;
self.calloutView.layer.borderWidth = 0.0;
self.calloutView.hidden = NO;
return self.calloutView;
}
Use this code to add an image for GMSMarker:
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = MARKER_POSITION;
marker.infoWindowAnchor = CGPointMake(0.44f, 0.45f);
marker.icon = [UIImage imageNamed:#"CustomMarkerImageName"];
You can also use this delegate method to provide custom view for additional info:
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {
InfoWindow *view = [[[NSBundle mainBundle] loadNibNamed:#"InfoWindow" owner:self options:nil] objectAtIndex:0];
view.name.text = #"Place Name";
view.description.text = #"Place description";
view.phone.text = #"123 456 789";
view.placeImage.image = [UIImage imageNamed:#"customPlaceImage"];
view.placeImage.transform = CGAffineTransformMakeRotation(-.08);
return view;
}
Check this answer as a reference: https://stackoverflow.com/a/16767124/2082569
If I understand correctly, the ask is to show the info window for a particular marker programmatically.
[self.mapView setSelectedMarker:marker];
To achieve camera refocus similar to if a user had tapped the marker, do something like:
GMSCameraPosition *cameraPosition =
[[GMSCameraPosition alloc] initWithTarget:marker.position
zoom:15
bearing:0
viewingAngle:0];
[self.mapView animateToCameraPosition:cameraPosition];

coloring and adding buttons to annotations in a mutable array in iOS

I am coding an application that uses a mapView in iOS.
I am trying to color the annotations in the mutable array to purple and to add a disclosure button to each pin .
The reason that I am using a mutable array is that I am going to retrieve many places from a DB to view each place on the map with a pin.
My code is :
- (void)viewDidLoad{
[super viewDidLoad];
// Do any additional setup after loading the view.
//code of map
[mapMKMapView setMapType:MKMapTypeStandard];
[mapMKMapView setZoomEnabled:YES];
[mapMKMapView setScrollEnabled:YES];
MKCoordinateRegion newRegion = { {0.0, 0.0},{0.0, 0.0}};
newRegion.center.latitude = 12.968427;
newRegion.center.longitude = 44.997704;
newRegion.span.latitudeDelta = 0.004731;
newRegion.span.longitudeDelta = 0.006952;
[self.mapMKMapView setRegion:newRegion animated:YES];
//multiple annotations
NSMutableArray *locations = [[NSMutableArray alloc] init ];
CLLocationCoordinate2D loc;
annotationClass *myAnn;
//1st annotation
myAnn = [[annotationClass alloc] init];
loc.latitude = 12.968427;
loc.longitude = 44.997704;
myAnn.coordinate = loc;
myAnn.title = #"Nakheel2";
myAnn.subtitle = #"This Al-Nakheel 2 stage";
[locations addObject:myAnn];
//2nd annotaion
myAnn = [[annotationClass alloc] init];
loc.latitude = 12.971532;
loc.longitude = 44.998015;
myAnn.coordinate = loc;
myAnn.title = #"Nakheel21";
myAnn.subtitle = #"This Al-Nakheel 2 stage Hi";
[locations addObject:myAnn];
[self.mapMKMapView addAnnotations:locations];
}
//******
-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)locations
{
MKPinAnnotationView *MyPin=[[MKPinAnnotationView alloc] initWithAnnotation:locations reuseIdentifier:#"current"];
MyPin.pinColor = MKPinAnnotationColorPurple;
UIButton *adverButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[adverButton addTarget:self action:#selector(button:) forControlEvents:UIControlEventTouchUpInside];
MyPin.rightCalloutAccessoryView = adverButton;
MyPin.draggable = NO;
MyPin.highlighted = YES;
MyPin.animatesDrop = TRUE;
MyPin.canShowCallout = YES;
return MyPin;
}
The viewForAnnotation delegate method will be called by the map view automatically (you don't explicitly "run" it).
The most likely reason the map view is not calling it is that the map view's delegate is not set.
In the storyboard or xib, make sure the map view's delegate outlet is connected to the view controller (right-click or ctrl-click the map view and connect the delegate outlet to the view controller).
Or, you can add this line in the code in viewDidLoad before the setMapType:
//code of map
mapMKMapView.delegate = self; // <-- add this line
[mapMKMapView setMapType:MKMapTypeStandard];
An unrelated point:
Instead of using a custom action method for the button, I suggest using the map view's own calloutAccessoryControlTapped delegate method. In that method, you'll get direct access to the annotation object that was tapped (via view.annotation). Remove the addTarget and the button: method if you decide to use the delegate method.

Adding AwesomeMenu over a MkMapView

I'm currently trying to add AwesomeMenu on top of a MapView.
The mapview is loaded via Storyboard and the AwesomeMenu is created in the "viewDidLoad" method of the view controller and then added as subview.
In this way AwesomeMenu doesn't show on the view, is there a particular problem on adding subviews to MKMapView? Any clue?
-(void)viewDidLoad
{
CLLocation *turin = [[CLLocation alloc] initWithLatitude:45.071274 longitude:7.684910];
MKCoordinateRegion region =
MKCoordinateRegionMakeWithDistance (
turin.coordinate, 1000, 1000);
[mapView setRegion:region animated:NO];
[switcher addTarget:self action:#selector(populateMap:) forControlEvents:UIControlEventValueChanged];
menu = [[AwesomeMenu alloc] initWithFrame:self.mapView.frame
menus:nil];
[self.mapView addSubview:menu];
}
Thanks in advance ...
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIImage *storyMenuItemImage = [UIImage imageNamed:#"bg-menuitem.png"];
UIImage *storyMenuItemImagePressed = [UIImage imageNamed:#"bg-menuitem-highlighted.png"];
UIImage *starImage = [UIImage imageNamed:#"icon-star.png"];
AwesomeMenuItem *starMenuItem1 = [[AwesomeMenuItem alloc] initWithImage:storyMenuItemImage
highlightedImage:storyMenuItemImagePressed
ContentImage:starImage
highlightedContentImage:nil];
NSArray *menuOptions = [NSArray arrayWithObjects:starMenuItem1 , nil];
AwesomeMenu *menu = [[AwesomeMenu alloc] initWithFrame:self.view.frame
menus: menuOptions];
[self.view addSubview:menu];
}

Resources