![](/img/trans.png)
[英]iOS Mapbox SDK - How to add MGLPointAnnotation markers into a map layer
[英]How can I add markers with custom images to Mapbox iOS?
我正在学习本教程: https : //www.mapbox.com/mapbox-ios-sdk/examples/marker-custom-image/,并且我有一个Web API,可从中获取纬度/经度/名称/ imageURL。
您可以在这里看到我的代码: http : //pastebin.com/eGtYSXR8
在第107行中,我想遍历响应并创建标记,同时为标记分配自定义图像,但是我不确定如何做到这一点。 我是Obj-C的新手,所以我不知道在何处调用此行,甚至不知道函数名是什么:
- (RMMapLayer *)mapView:(RMMapView *)mapView layerForAnnotation:(RMAnnotation *)annotation
谁能指出我正确的方向? 我了解如何在MapBox上创建标记,但是图像似乎是在其他函数中创建的,无法传递变量。
您也应该阅读Cocoa中的委托模式,并且可以使用-[RMAnnotation userInfo]
传递带有可在委托回调中使用的注释的任意信息。
首先,您应该创建RMAnnotation并将此注释添加到地图。
_userLocation = [RMAnnotation annotationWithMapView:_mapView
coordinate:CLLocationCoordinate2DMake(0.011774,0.002308)
andTitle:nil];
[_mapView addAnnotation:_userLocation];
第二
- (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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.