2014-03-04 122 views
0

我是新來使用RMPolylines和RMShapes和我認爲我正確地執行這個代碼,但沒有什麼是地圖上顯示了:的iOS MapBox RMShape

RMMapBoxSource *tilesource = [[RMMapBoxSource alloc] initWithMapID:kMapID]; 

[mapView setTileSource:tilesource]; 

NSArray *locations = [NSArray arrayWithObjects:[[CLLocation alloc] initWithLatitude:-33.981595 longitude:151.072900],[[CLLocation alloc] initWithLatitude:-33.981560 longitude:151.073544],[[CLLocation alloc] initWithLatitude:-33.981560 longitude:151.073845],[[CLLocation alloc] initWithLatitude:-33.981666 longitude:151.074016], nil]; 

RMAnnotation *annoation43 = [[RMAnnotation alloc] initWithMapView:mapView coordinate:((CLLocation *)[locations objectAtIndex:0]).coordinate andTitle:@"Hola biatches!"]; 

annoation43.userInfo = locations; 
[annoation43 setBoundingBoxFromLocations:locations]; 
[mapView addAnnotation:annoation43]; 

-(RMMapLayer *)mapView:(RMMapView *)mapViewer layerForAnnotation:(RMAnnotation *)annotation 
{ 
    if (annotation.isUserLocationAnnotation) 
     return nil; 

    RMShape *shape = [[RMShape alloc] initWithView:mapView]; 

    shape.lineColor = [UIColor orangeColor]; 
    shape.lineWidth = 5.0; 

    for (CLLocation *location in (NSArray *)annotation.userInfo) 
     [shape addLineToCoordinate:location.coordinate]; 

    return shape; 
    NSLog(@"It is working Dora!"); 
} 

因此,我認爲我做錯了這裏,但我無法挑選 - 如果需要更多代碼或信息,請告訴我。

回答

0

好吧現在已經修好了,好像是一個簡單的問題,但是如果你知道詳細的原因,我很樂意聽到它!

添加以下內容:

mapView.delegate = self; 

我以爲我已經設置委託,但顯然不是!

+0

是的,你肯定會需要一個委託集來使用'-mapView:layerForAnnotation:'委託方法。 – incanus

0

首先,您的NSLog()因爲return而不會運行,但那是次要的。

我看到你基本上跟着shape example。我不確定什麼是錯的。愚蠢的問題,但是屏幕上的形狀?即您的地圖視圖顯示此形狀覆蓋的區域?

+0

哈哈是的,我只是注意到日誌。 是的,只要我可以告訴屏幕上的形狀,因爲我也嘗試將mapID更改爲MapBox示例地圖ID,但仍然沒有顯示出來。但是,如果我「複製,粘貼代碼」EXACT形狀示例,示例RMShape行顯示。我將瀏覽我的代碼並嘗試發佈更多可能相關的信息。 – jkd359