将MKMapView点移动到像素坐标 [英] Move MKMapView point to pixel coordinates

查看:111
本文介绍了将MKMapView点移动到像素坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简短的问题.我将自定义视图用作地图视图的标注附件.我在使注释移动到所说视图的右下角时遇到一些问题.我目前正在尝试获取所选批注的CGPoint坐标,但是除此之外,我已将所有内容绘制为空白.非常感谢您的帮助.

I have a quick question. I am using a custom view as a callout accessory for my map view. I am having some issues with getting the annotation to move to the right bottom corner of the said view. I am currently trying to get the CGPoint coords of the selected annotation, but beyond that I've drawn a blank Any help would be greatly appreciated.

我正在使用的当前代码(我知道这是不正确的:)

The current code I'm using (I know it is incorrect is:)

   CGPoint bottomLeftPoint = CGPointMake(xOffset,[self.internalAnnotationCallout view].frame.size.height);
CLLocationCoordinate2D bottomLeftCoord = [self.branchLocation convertPoint:bottomLeftPoint toCoordinateFromView:self.branchLocation];
MKCoordinateSpan span = {latitudeDelta: kMapMultiLatDelta, longitudeDelta: kMapMultiLatDelta};
  MKCoordinateRegion region = {bottomLeftCoord, span};
 [self.branchLocation setRegion:region animated:YES];
//[self.branchLocation setCenterCoordinate:newCenterCoordinate animated:YES];

推荐答案

好吧,所以我稍微弄混了一点,并且能够将一些看起来可行的东西放在一起,希望我现在真正了解您要实现的目标!

Ok so I messed around with this a little and was able to to put something together that seems to work, hoping that I now actually understand what you're trying to achieve!

- (void)shiftToCorner{
    //ignore "Annotation", this is just my own custom MKAnnotation subclass
    Annotation *currentAnnotation = [[mapView selectedAnnotations] objectAtIndex:0];
    [mapView setCenterCoordinate:currentAnnotation.coordinate];

    CGPoint fakecenter = CGPointMake(20, 20);
    CLLocationCoordinate2D coordinate = [mapView convertPoint:fakecenter toCoordinateFromView:mapView];
    [mapView setCenterCoordinate:coordinate animated:YES];
}

让我快速解释一下它的作用;假设您希望注解移动到地图视图右边缘起20个点和底部边缘起20个点的位置.如果考虑一下,如果当前注释位于地图视图的中心,则到此点的距离与到(20,20)的距离相同.这意味着我们可以通过以下方式将注释发送到此点:首先将地图视图以注释为中心,然后将动画设置为(20,20).

Let me quickly explain what this does; Let's say you want your annotation to move to a position 20 points in from the right edge and 20 points up from the bottom edge of the map view. If you think about it, if the current annotation is at the center of the map view, then the distance to this point is the same as the distance to (20, 20). This means that we can send our annotation to this point by first centering our map view on the annotation, then animating to (20, 20).

这篇关于将MKMapView点移动到像素坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆