Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在mkmapview上显示多个位置点_Ios_Objective C_Annotations_Mkmapview_Mkannotationview - Fatal编程技术网

Ios 如何在mkmapview上显示多个位置点

Ios 如何在mkmapview上显示多个位置点,ios,objective-c,annotations,mkmapview,mkannotationview,Ios,Objective C,Annotations,Mkmapview,Mkannotationview,如何在mkmapview上获取多个位置接点 在我的当前位置,我查看我的朋友向我注册 我有位置纬度和经度值 以下是用于理解的虚拟值 想在mapView上显示我所有的朋友,并显示他们的位置吗 使用PinPointer Marker.png放置 //创建了地图视图 mapView = [[MKMapView alloc] init]; mapView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.he

如何在mkmapview上获取多个位置接点

在我的当前位置,我查看我的朋友向我注册

我有位置纬度和经度值

以下是用于理解的虚拟值

想在mapView上显示我所有的朋友,并显示他们的位置吗 使用PinPointer Marker.png放置

//创建了地图视图

mapView = [[MKMapView alloc] init];
mapView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-60);
mapView.delegate = self;
mapView.mapType = MKMapTypeStandard;
mapView.showsUserLocation = YES;
[self.view addSubview:mapView];
mkmarkerpin指针


你需要在你的朋友之间循环你是否将他们存储在数组或其他什么东西中??然后为每个项调用addAnnotation

比如:

for (Friend *friend in friends){
   CLLocationCoordinate2D coordinate;
   coordinate.latitude = latitude.doubleValue;
   coordinate.longitude = longitude.doubleValue;
   MKPointAnnotation *myAnnotation = [[MKPointAnnotation alloc] init];
   myAnnotation.coordinate = coordinate;
   [mapView addAnnotation:annotation];
}
然后,将自动调用已经实现的方法mapView:viewForAnnotation:并添加注释。查看本教程了解更多信息:

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
    static NSString *AnnotationViewID = @"annotationView";

    MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];

    if (annotationView == nil){
        annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];
    }

    annotationView.image = [UIImage imageNamed:@"Marker.png"];
    annotationView.annotation = annotation;

    return annotationView;
}
for (Friend *friend in friends){
   CLLocationCoordinate2D coordinate;
   coordinate.latitude = latitude.doubleValue;
   coordinate.longitude = longitude.doubleValue;
   MKPointAnnotation *myAnnotation = [[MKPointAnnotation alloc] init];
   myAnnotation.coordinate = coordinate;
   [mapView addAnnotation:annotation];
}