【问题标题】:How to show multiple location points on mkmapview如何在 mkmapview 上显示多个位置点
【发布时间】:2014-11-30 03:12:25
【问题描述】:

如何在 mkmapview 上获取多个定位点。

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

我有位置纬度和经度值。

以下是用于理解的虚拟值。

{
friendA:
{
latitude: "12.1234";
longtitude: "12.1234";
},

friendB:
{
latitude: "12.1234";
longtitude: "12.1234";
},

friendD:
{
latitude: "12.1234";
longtitude: "12.1234";
}

}

想在 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];

MKAnnotation MarkerPin 指针

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

【问题讨论】:

    标签: ios objective-c annotations mkmapview mkannotationview


    【解决方案1】:

    您需要遍历您的朋友(您是否将他们存储在数组或其他东西中??)然后为每个项目调用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: 被自动调用并添加注释。查看本教程了解更多信息:http://www.devfright.com/mkpointannotation-tutorial/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-30
      • 2011-11-14
      • 2012-01-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多