2011-09-23 31 views
11

Tôi đã đặt để MKMapView hiển thị vị trí hiện tại. Tôi cũng có một pin tùy chỉnh được thực hiện cho các chân khác. Tuy nhiên, nó chỉ ra vị trí hiện tại cho thấy như là một pin tùy chỉnh, trong khi tôi chỉ muốn nó là một vòng tròn màu xanh thường xuyên (như những gì bản đồ google có).MKMapView vị trí hiện tại hiển thị dưới dạng ghim tùy chỉnh

tôi đã xác định như sau trong mã của tôi:

- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation: (id<MKAnnotation>) annotation MKAnnotationView *pin = (MKAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier: @"VoteSpotPin"]; 
    if (pin == nil) 
    { 
     pin = [[[MKAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"TestPin"] autorelease]; 
    } 
    else 
    { 
     pin.annotation = annotation; 
    } 

    [pin setImage:[UIImage imageNamed:@"TestPin.png"]]; 
    pin.canShowCallout = YES; 
    pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    return pin; 
} 

Làm thế nào tôi có thể ngăn chặn các vị trí hiện tại để hiển thị như một pin?

+1

mapView.showsUserLocation = YES thì nó sẽ hiển thị vị trí hiện tại .Nếu bạn muốn hiển thị pin ở vị trí hiện tại vượt qua lon vị trí lat hiện hành để chú thích; – Srinivas

+0

Tôi đã làm điều đó và nó cho thấy vị trí hiện tại như một pin tùy chỉnh tôi có và không phải là vòng tròn màu xanh. Đó thực sự là vấn đề thực sự – adit

+0

bạn có kiểm tra ứng dụng của bạn có hỗ trợ trình quản lý vị trí. Trong thiết bị hoặc trình mô phỏng – Srinivas

Trả lời

24

bạn cần phải thực hiện điều này: -

- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation:(id<MKAnnotation>) annotation 
{   
    if (annotation == mapView.userLocation) 
    { 
     return nil; 
    } 
    else 
    { 
     MKAnnotationView *pin = (MKAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier: @"VoteSpotPin"]; 
     if (pin == nil) 
     { 
      pin = [[[MKAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"TestPin"] autorelease]; 
     } 
     else 
     { 
      pin.annotation = annotation; 
     }   

     [pin setImage:[UIImage imageNamed:@"TestPin.png"]]; 
     pin.canShowCallout = YES; 
     pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
     return pin; 
    } 
} 
+1

không biết rằng mapView.userLocation cũng là một chú thích hay không. Cảm ơn! vui mừng khi biết điều này – adit

0
- (MKAnnotationView *)mapView:(MKMapView *)mapViewTmp viewForAnnotation:(id<MKAnnotation>)annotation 
    { 
     if(annotation == mapView.userLocation) 
      return nil; 
     else 
      { 
MKAnnotationView *pin = (MKAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier: @"VoteSpotPin"]; 
      if (pin == nil) 
      { 

       pin = [[[MKAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"TestPin"] autorelease]; 
      } 
      else 
      { 
       pin.annotation = annotation; 
      } 

      [pin setImage:[UIImage imageNamed:@"TestPin.png"]]; 
      pin.canShowCallout = YES; 
      pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
      return pin; 
     } 

    } 
0

Muốn giải pháp đơn giản nhất? Chỉ cần thay đổi mã pin đối tượng của bạn từ MKAnnotationView thành MKPinAnnotationView nó sẽ hiển thị cho bạn những gì bạn muốn.

0
mapView.delegate=self; 



MKCoordinateRegion myRegion; 

CLLocationCoordinate2D center; 

center.latitude=40.4000;//spean 

center.longitude=-3.6833;//firstLagi;//-5.345373; 



MKCoordinateSpan span; 

span.latitudeDelta=My_Span; 
span.longitudeDelta=My_Span; 


myRegion.center=center; 
myRegion.span=span; 


[mapView setRegion:myRegion animated:YES]; 



NSMutableArray *locations=[[NSMutableArray alloc]init]; 

CLLocationCoordinate2D location; 
Annotation *myAnn; 




allList=[[AllList alloc]init]; 




for (int j = 0; j<[appDelegate.allListArray count]; j++) 
{ 
    [email protected]"cat"; 
    myAnn=[[Annotation alloc]init]; 

    allList=[appDelegate.allListArray objectAtIndex:j]; 

    location.latitude=[allList.lati doubleValue]; 
    location.longitude=[allList.lagi doubleValue]; 

    myAnn.coordinate=location; 
    myAnn.title=allList.name; 
    //myAnn.subtitle=allList.type; 

    [locations addObject:myAnn]; 


} 

[self.mapView addAnnotations:locations]; 
2

Đối Swift:

if annotation is MKUserLocation { 
    return nil 
} 
Các vấn đề liên quan