我正在开发和iphone应用程序,我正在使用Mappy SDK IOS。
我到了显示地图并显示我当前的位置。但我在地图上添加一些标记时遇到问题。
我有一个NSArray,其中包含一些具有经度和纬度属性的对象。 我显示标记的代码是:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
//initialisation mot de passe + user
[MPInit initialisation:MAPPY_API_KEY];
[RMMapView class];
//show user location
self.mapView.showsUserLocation = NO;
self.mapView.showPoi = YES;
//set delegate
self.mapView.delegate = self;
MPMarkerManager *markerManager = [self.mapView markerManager];
MPMarkerCategory * category = [markerManager getCategory:@"storeLocations"];
//remove old elements
[category.dataSource removeAllElements];
//add markers on map
for(int i=0; i<self.arrayStores.count; i++) {
NSLog(@"add store %d on the map", i);
NSDictionary* currentStore = [self.arrayStores objectAtIndex:i];
float latitude = [[currentStore objectForKey:@"latitude"] floatValue];
float longitude = [[currentStore objectForKey:@"longitude"] floatValue];
CLLocationCoordinate2D locationStore = CLLocationCoordinate2DMake(latitude, longitude);
//create a new POI object with location
MPPoi * poi = [[MPPoi alloc] initWithUId:[currentStore objectForKey:@"title"] withLocation:locationStore];
[category.dataSource addElement:poi];
self.mapView.centerCoordinate = locationStore;
[poi release];
}
//category settings
category.markerColor = [UIColor greenColor];
//[category setOptimalZoom:YES];//set the zoom to be optimal : show all poi in the category
[category setHideLabelOnTheFirstShow:NO];
[category setAnimateAtFirstShow:YES];
}
以下是控制台上显示的日志:
2012-06-14 17:01:18.359 Koutoubia[609:607] MappyKit version:1.40
2012-06-14 17:01:18.672 Koutoubia[609:607] add store 0 on the map
我正在做错事吗?因为没有显示标记
在文档上添加标记的文档是:
//add a marker on map
MPMarkerManager *markerManager = [viewController.mapView markerManager];
MPMarkerCategory * category = [markerManager getCategory:HMP_LOC_CATEGORY];
//remove old elements
[category.dataSource removeAllElements];
//create a new POI object with location
MPPoi * poi = [[MPPoi alloc] initWithUId:locationData.address withLocation:findLocation];
[category.dataSource addElement:poi];
[poi release];
文档的链接是here
任何想法?提前谢谢
答案 0 :(得分:0)
我已经创建了解决方案,
问题是我忘了初始化MPMarkerCategory
并将其添加到markerManager
方法的viewDidLoad
:
//Marker initialization
MPMarkerManager *markerManager = [self.mapView markerManager];
//add a new category with green default color
[markerManager addCategory:STORE_LOC_CATEGORY withColor:[UIColor greenColor]];