【问题标题】:Image instead of a the default pin in iPhone's MapKit framework?图像而不是 iPhone 的 MapKit 框架中的默认引脚?
【发布时间】:2013-07-25 15:39:09
【问题描述】:

是否可以在 iPhone 上使用我们自己的图像而不是 MapKit 地图中的默认图钉?

我正在开发一个应用程序,该应用程序可以显示朋友的位置,就像谷歌纵横一样,并且需要在他们的位置显示朋友的图像。

可以使用 JavaScript 谷歌地图,但我想知道是否有人可以为基于 MapKit 的地图提供一些示例代码。

【问题讨论】:

    标签: iphone google-maps mapkit


    【解决方案1】:

    是的,这是可能的。 为此,您必须使用 MKAnnotationView 而不是 MKPinAnnotationView。 并且不要使用 annotation.animatesDrop 属性。

    这是您可以在 viewForAnnotation 中使用的示例代码,

        annotation = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"try"];
        annotation.canShowCallout = YES;
    
        annotation.image = [UIImage imageNamed:@"image.png"];
    
    
        return annotation;
    

    【讨论】:

    • 谢谢。它成功了。真不敢相信我竟然想不出这么简单的把戏。
    【解决方案2】:

    您还可以设置图像的框架。对于上面的代码,我们必须做这个简单的改变。

    UIImage *pinImage = [UIImage imageNamed:@"image.png"];
    
    UIImageView *imageView = [[[UIImageView alloc] initWithImage:pinImage] autorelease];
    
           imageView.frame = CGRectMake(-20, 0, 40, 30);
    
    [annotation addSubview:imageView];
    

    我们必须评论这一行

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

    【讨论】:

      【解决方案3】:

      通过使用 span 属性,您可以轻松缩放到您的要求

      MKCoordinateSpan 跨度;

      MKCoordinateRegion region;
      
      
      mapView.scrollEnabled=YES;
      span.latitudeDelta = 100.0;//more value you set your zoom level will increase
      span.longitudeDelta =100.0;//more value you set your zoom level will increase
      mapView.showsUserLocation=YES;
      region.span = span;
      
      
      region.center = from.coordinate;
        [mapView setRegion:region animated:YES];
       [mapView regionThatFits:region];
      [mapView addAnnotation:from];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-11-16
        • 1970-01-01
        • 2011-01-06
        • 1970-01-01
        • 2015-03-17
        • 1970-01-01
        • 1970-01-01
        • 2022-10-16
        相关资源
        最近更新 更多