ios如何在地图视图中移动图钉?

时间:2013-02-25 06:32:49

标签: ios6 mapkit

最近我开始研究与地图相关的项目。我的应用程序的流程,我想在地图上显示我朋友的时刻。我有一个后端服务器,它有关于这些人的当前位置的准确信息。所以,我可以从我的服务器获取他们的lats& longs的信息。但唯一的问题是如何在地图上显示他们的时刻,就像我的当前位置引脚指针一样?当我刷新具有更新位置的地图时,引脚应移动到新位置。你能帮帮我怎样才能同时将不同的针脚移动到不同的位置?

1 个答案:

答案 0 :(得分:0)

试试这段代码,非常有用:

// Map view view annotation delegate method
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:
(id <MKAnnotation>)annotation
{
    MKPinAnnotationView *pinView = nil;
    if(annotation != mapView.userLocation)
    {
        static NSString *defaultPinID = @"com.invasivecode.pin";
        pinView = (MKPinAnnotationView *)[_ex_map_view dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( pinView == nil ) pinView = [[MKPinAnnotationView alloc]
                                          initWithAnnotation:annotation reuseIdentifier:defaultPinID];
        [pinView setDraggable:YES];
        pinView.pinColor = MKPinAnnotationColorRed;
        pinView.canShowCallout = YES;
        pinView.animatesDrop = YES;
    }
    else
    {
        [mapView.userLocation setTitle:@"I am here"];
    }
    return pinView;
}