Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.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
在iPhone MKMapView中显示用户位置蓝点_Iphone_Ios_Mapkit_Mkmapview_Mkannotationview - Fatal编程技术网

在iPhone MKMapView中显示用户位置蓝点

在iPhone MKMapView中显示用户位置蓝点,iphone,ios,mapkit,mkmapview,mkannotationview,Iphone,Ios,Mapkit,Mkmapview,Mkannotationview,我正在iPhone应用程序的MapView中开发自定义PIN。 代码如下: - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { static NSString *AnnotationViewID = @"annotationViewID"; MKAnnotationView *annotationView =

我正在iPhone应用程序的MapView中开发自定义PIN。 代码如下:

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

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

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

    if ([[annotation title] isEqualToString:NSLocalizedString(@"Current Location",@"")])  {

        MKPinAnnotationView *pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
        //pin.pinColor = MKPinAnnotationColorRed;
        annotationView = pin;
    }
    else
    {
        NSString *pin = [NSString stringWithFormat:@"pin%i.png",[[annotation imgNumber] intValue]];
        annotationView.image = [UIImage imageNamed:pin];//Canviar la chincheta per numero
        UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [annotationView setRightCalloutAccessoryView:button];
        annotationView.annotation = annotation;
        annotationView.canShowCallout = YES;

    /********* Imagen a la izquierda en la burbuja *********/
    annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    // Set up the Left callout
    UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeCustom];
    myDetailButton.frame = CGRectMake(0, 0, 23, 23);
    myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;

    // Set the image for the button
    //[myDetailButton setImage:[UIImage imageNamed:@"botocorreu.png"] forState:UIControlStateNormal];
    NSString *detailButton = [NSString stringWithFormat:@"%i",[[annotation imgNumber] intValue]];
    [myDetailButton setImage:[UIImage imageNamed:detailButton] forState:UIControlStateNormal];  
    // Set the button as the callout view
    annotationView.leftCalloutAccessoryView = myDetailButton;
    annotationView.canShowCallout = YES;
    }
     return annotationView;
  }
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释
{
静态NSString*AnnotationViewID=@“AnnotationViewID”;
MKAnnotationView*annotationView=(MKAnnotationView*)[myMapView出列重用AnnotationViewWithIdentifier:AnnotationViewID];
如果(注释视图==nil)
{
annotationView=[[MKAnnotationView alloc]initWithAnnotation:annotation重用标识符:AnnotationViewID]自动释放];
}
if([[annotation title]IsequalString:NSLocalizedString(@“当前位置”,“@”)){
MKPinAnnotationView*pin=[[MKPinAnnotationView alloc]initWithAnnotation:annotation重用标识符:AnnotationViewID]自动释放];
//pin.pinColor=MKPinAnnotationColorRed;
注释视图=引脚;
}
其他的
{
NSString*pin=[NSString stringWithFormat:@“pin%i.png”,[[annotation imgNumber]intValue]];
annotationView.image=[UIImage ImageName:pin];//每一个数字都有一个中国人
UIButton*button=[UIButton button类型:UIButtonTypedTailButton];
[注释视图setRightCalloutAccessoryView:按钮];
annotationView.annotation=注释;
annotationView.canShowCallout=是;
/*********在布贾的伊兹基尔达酒店*********/
annotationView.rightCalloutAccessoryView=[UIButton Button,类型:UIButtonTypedTailDisclosure];
//设置左详图索引
UIButton*myDetailButton=[UIButton按钮类型:UIButtonTypeCustom];
myDetailButton.frame=CGRectMake(0,0,23,23);
myDetailButton.contentVerticalAlignment=uicontrolContentVerticalAlignment中心;
myDetailButton.contentHorizontalAlignment=uicontrolContentHorizontalAlignment中心;
//设置按钮的图像
//[myDetailButton setImage:[UIImage ImageName:@“botocorreu.png”]用于状态:UIControlStateNormal];
NSString*detailButton=[NSString stringWithFormat:@“%i”,[[annotation imgNumber]intValue]];
[myDetailButton setImage:[UIImage ImageName:detailButton]用于状态:UIControlStateNormal];
//将按钮设置为详图索引视图
annotationView.leftCalloutAccessoryView=myDetailButton;
annotationView.canShowCallout=是;
}
返回注释视图;
}
这很好,但是用一个红色的pin向我显示用户的位置。 我检查IB中的“显示用户位置”。 我想使用默认的蓝点,它会在用户移动时自动移动,对吗? 我该怎么做


非常感谢。

将此添加到
viewForAnnotation
方法的顶部

if ([annotation isKindOfClass:[MKUserLocation class]])
    return nil;
特殊用户位置注释的类型为
MKUserLocation
,在这种情况下返回nil告诉地图视图为其绘制默认视图,即蓝点

您还可以删除这些行,因为不再需要它们:

if ([[annotation title] isEqualToString:NSLocalizedString(@"Current Location",@"")])  {
    MKPinAnnotationView *pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
    //pin.pinColor = MKPinAnnotationColorRed;
    annotationView = pin;
}
else

很好用,thnks。唯一的问题是显示用户位置的蓝点,使他周围有一个很大的圆圈,它是否可计算成本?圆圈大小表示位置有多精确(越小意味着越精确)。不确定是否可以使用CLLocationManager.ok thnks在MKMapView中控制此操作。您知道如何通过编写userlocation来手动引入代码。我需要把用户放在一个地方。Thnksun幸运的是,动画蓝点视图不适用于您自己的注释视图,并且您不能覆盖地图视图的用户位置坐标。可以在特定位置创建自己的注释,但不能使其使用蓝点动画。您必须自己绘制它,或者拍摄圆点的屏幕截图,并将其用作注释视图中的图像。