Текущее местоположение MKMapView, отображаемое как пользовательские контакты
Я установил так, чтобы мой MKMapView показывал текущее местоположение. У меня также есть пользовательский PIN-код, который используется для других контактов. Тем не менее, оказывается, что текущее местоположение отображается как пользовательский вывод, тогда как я просто хотел, чтобы он был обычным синим кругом (например, что такое карта google).
В моем коде я определил следующее:
- (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
вам нужно реализовать это: -
- (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;
}
}
Ответ 2
Для Swift:
if annotation is MKUserLocation {
return nil
}
Ответ 3
- (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;
}
}
Ответ 4
Хотите простейшее решение? Просто измените контакт объекта с MKAnnotationView
на MKPinAnnotationView
, он покажет вам, что вы хотите.
Ответ 5
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];