0
votes

I am following this tutorial: https://www.mapbox.com/mapbox-ios-sdk/examples/marker-custom-image/ and I have a web API that I am getting latitude/longitude/name/imageURL from.

You can see my code here: http://pastebin.com/eGtYSXR8

At line 107 I would like to for loop through the response and create the markers while at the same time assigning the custom image for the marker but I'm not sure how i can do that. I am new to Obj-C so I don't understand where this line is being called or what the function name is even:

- (RMMapLayer *)mapView:(RMMapView *)mapView layerForAnnotation:(RMAnnotation *)annotation

Can anyone point me in the right direction? I understand how markers are created on MapBox, but the image seems to be created in a different function with no ability to pass a variable.

2
I have looked your code. RMMapView already have method -mapView:didUpdateUserLocation: in it's delegate to notify about location changes. Set the RMMapView's showsUserLocation property to YESAzat

2 Answers

1
votes

You should read up on the delegate pattern in Cocoa, too, and you can make use of -[RMAnnotation userInfo] to pass arbitrary info with your annotation that can be used in the delegate callback.

0
votes

At first you should to create RMAnnotation and add this annotation to the map.

_userLocation = [RMAnnotation annotationWithMapView:_mapView
                                            coordinate:CLLocationCoordinate2DMake(0.011774,0.002308)
                                             andTitle:nil];
[_mapView addAnnotation:_userLocation];

Second

- (RMMapLayer *)mapView:(RMMapView *)mapView layerForAnnotation:(RMAnnotation *)annotation
{
    marker = [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:@"userPin"]];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 80, 80)];
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    marker.leftCalloutAccessoryView = imageView;
    return marker;
}