返回列表 回覆 發文

[Objective-C] MKMapView地圖畫面 圖示顯示

請問在MapView上好像只能載入一種圖案(大頭針or自訂圖片)
之後不論怎麼呼叫都只能顯示一種圖案
我想在大頭針之後加入路徑的
  1. - (void)viewDidLoad {
  2.     [super viewDidLoad];
  3.        
  4.         CGRect rect = CGRectMake(0, 0, 320, 460);
  5.         map1 = [[MKMapView alloc] initWithFrame:rect];
  6.         map1.delegate=self;
  7.         map1.mapType=MKMapTypeHybrid;

  8.         NSURL *url = [NSURL URLWithString:@"網址"];
  9.         parser = [[RSSParser alloc] init];
  10.         [parser parseWithUrl:url];
  11.         xmlContent = [parser result];
  12.        
  13.         MKCoordinateRegion theRegion;
  14.         CLLocationCoordinate2D theCenter;
  15.         theCenter.latitude =23.468105445;               
  16.         theCenter.longitude = 120.9203527;
  17.        
  18.         MKCoordinateSpan theSpan;
  19.         theSpan.latitudeDelta = 0.056;
  20.         theSpan.longitudeDelta = 0.056;       
  21.        
  22.         theRegion.span = theSpan;
  23.         theRegion.center= theCenter;

  24.         map1.scrollEnabled = YES;
  25.         map1.zoomEnabled = YES;
  26.        
  27.         [map1 setRegion:theRegion];
  28.         [map1 regionThatFits:theRegion];
  29.         [code][self createMapPoint:map1 coordinateX:latX coordinateY:lngY Title:chName Subtitle:date];
複製代碼
[self.view addSubview:map1];        [/code]

每次呼叫圖片皆是使用 (但只能呼叫同種圖片)
  1. [self createMapPoint:map1 coordinateX:latX coordinateY:lngY Title:chName Subtitle:date];
複製代碼
問題來了..我想使用不同的圖片..例如畫一條路徑相連在二個大頭針之間...
該如何才能把中間的路徑畫出來呢?   

希望大家能指點一下~ 謝謝! (^^)
可不可以換顆腦袋... 0rz
[會心一笑]:
這麼說好了...
你可以把路徑當作是另外一張圖,而你需要做的是動態畫出這張圖,然後放在你想放的位置,
目前大部分路徑的作法都是這樣,就是把路徑本身也是MKAnnotation,
如果不是路徑的應用,常見的就是塞subview進去,不過同樣的...
如果你不能預期要顯示的東西,那就要動態產生,
另外就是你的CreateMapPoint不是真正讓圖顯示的地方,
而是mapView:viewForAnnotation:的delegate function,
所以你每次只能用同一張圖,是因為你沒有在這裡判斷是不是要換圖,
畫路徑的話一樣也是要在這裡改圖,加油囉
[會心一笑]:
原來如此..^^
謝謝C大!!
可不可以換顆腦袋... 0rz
[會心一笑]:
返回列表