2011-09-23 21 views
11

MKMapView'ımın geçerli konumu gösterecek şekilde ayarladım. Ayrıca diğer iğneler için uygulanan özel bir pin var. Ancak, mevcut konum özel bir pim olarak gösteriliyor, oysa ben sadece normal bir mavi daire olmasını istedim (google haritasının sahip olduğu gibi).MKMap Geçerli konum özel pingler olarak gösteriliyor

- (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; 
} 

Nasıl bir pin olarak göstermek için mevcut konumu önleyebilir:

benim kodunda aşağıdaki tanımladık?

+1

mapView.showsUserLocation = EVET o zaman mevcut konumu gösterecektir; – Srinivas

+0

Bunu yaptım ve şu anki konumu mavi daire değil, sahip olduğum özel bir iğne olarak gösteriyor. Bu aslında gerçek sorun – adit

+0

uygulamanızın cihaz veya simülatör – Srinivas

cevap

24

Bunu uygulamak gerekir: -

- (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

konum manager.issue destekler olduğunu kontrol ettiniz mi mapView.userLocation bir ek açıklama olduğunu bilmiyordum. Teşekkürler! bunu bilmek sevindim – 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

en basit çözüm istiyor? Sadece nesne pininizi MKAnnotationView'dan MKPinAnnotationView'a değiştirin, ne istediğinizi gösterecektir.

Swift için
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

: o açıklama mevcut konum enlem, boylam geçmesi anki yerde pimi göstermek istiyorum .eğer

if annotation is MKUserLocation { 
    return nil 
} 
İlgili konular