2011-09-23 9 views
11

मैंने सेट किया है ताकि मेरा MKMapView वर्तमान स्थान दिखाता हो। मेरे पास अन्य पिन के लिए एक कस्टम पिन भी लागू है। हालांकि, यह वर्तमान पिन शो को कस्टम पिन के रूप में दिखाता है, जबकि मैं चाहता था कि यह एक नियमित नीला सर्कल बन जाए (जैसे Google मानचित्र में)।MKMapView वर्तमान पिन कस्टम पिन के रूप में दिखा रहा है

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

मैं कैसे एक पिन के रूप में दिखाने के लिए वर्तमान स्थान को रोका जा सकता:

मैं अपने कोड में निम्नलिखित को परिभाषित किया है?

+1

mapView.showsUserLocation = हाँ तो यह वर्तमान स्थान हैं.यदि आप वर्तमान स्थान पर पिन पता चलता है कि एनोटेशन के लिए वर्तमान स्थान अक्षांश देशांतर पारित चाहते दिखाई देगा; – Srinivas

+0

मैंने ऐसा किया और यह वर्तमान स्थान को मेरे पास एक कस्टम पिन के रूप में दिखाता है, न कि नीला सर्कल। वास्तव में यह वास्तविक मुद्दा है – adit

+0

क्या आपने जांच की है कि आपका एप्लिकेशन डिवाइस मैनेजर का समर्थन करता है या सिम्युलेटर – Srinivas

उत्तर

24

आप इस लागू करने की आवश्यकता: -

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

में उपयोगकर्ता का पता नहीं लगाता है कि mapView.userLocation भी एक एनोटेशन है। धन्यवाद! यह जानकर खुशी हुई – 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

सरल समाधान करना चाहते हैं? बस अपने ऑब्जेक्ट पिन को MKAnnotationView से MKPinAnnotationView पर बदलें, यह आपको दिखाएगा कि आप क्या चाहते हैं।

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

स्विफ्ट के लिए:

if annotation is MKUserLocation { 
    return nil 
} 
संबंधित मुद्दे