标签: mapkit

使用真实分辨率将MKMapView渲染为UIImage

我正在使用此函数将MKMapView实例渲染为图像:

@implementation UIView (Ext)
- (UIImage*) renderToImage
{
  UIGraphicsBeginImageContext(self.frame.size);
  [self.layer renderInContext:UIGraphicsGetCurrentContext()];
  UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext(); 
  return image;
}
Run Code Online (Sandbox Code Playgroud)

这很好用.但是使用iphone4时,渲染图像的分辨率与设备上的分辨率不同.在设备上我具有640x920地图视图质量,渲染图像具有320x460的分辨率.然后我将提供给UIGraphicsBeginImageContext()函数的大小加倍,但填充了唯一的左上角图像部分.

问题:有没有办法将地图渲染为具有全分辨率640x920的图像?

iphone uiimage mapkit

8
推荐指数
1
解决办法
3095
查看次数

点击触摸缩放mapView

我正试图抓住触摸事件的坐标.我可以抓住,但是当给变焦有大数字时,我把它放在一个函数中

newCoord = [mapView convertPoint:location toCoordinateFromView:mapView],
Run Code Online (Sandbox Code Playgroud)

我的坐标错了.我能做什么?

我的代码:

UITouch *touch = [touches anyObject];

CGPoint location = [touch locationInView:touch.view];


NSLog(@"locationTOUCH:%f,%f", location.x,location.y);

CLLocationCoordinate2D newCoord;

newCoord = [mapView convertPoint:location toCoordinateFromView:mapView];

NSLog(@"coordinate-%f,%f", newCoord.latitude,newCoord.longitude); 
Run Code Online (Sandbox Code Playgroud)

iphone mapkit ios4 ios

8
推荐指数
1
解决办法
343
查看次数

MKOverlay有时会消失

我的地图中有两个叠加选项:MKCircleOverlay和MKPolygonOverlay.第一个是可变半径,通过UISlider控制.最后一个是根据角的数量和位置自定义.如果我改变非常快的圆的半径(减少UISlider的值)有时候我的叠加层会消失(圆圈),之后不能再绘制多边形了(当然也是圆圈).没有崩溃的应用程序.可能是什么?

这是我使用的一些代码:

- (IBAction) addCircle:(id)sender
{
slider.hidden = NO;
slider.transform = CGAffineTransformMakeRotation(M_PI*(-0.5));

_longPressRecognizer= [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
_longPressRecognizer.minimumPressDuration = 1.0; 

[mapview addGestureRecognizer:_longPressRecognizer];
[_longPressRecognizer release];
}

- (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state != UIGestureRecognizerStateBegan)
    return;
CGPoint touchPoint = [gestureRecognizer locationInView:mapview];    
CLLocationCoordinate2D touchMapCoordinate = [mapview convertPoint:touchPoint toCoordinateFromView:mapview];

MKPointAnnotation *pa = [[MKPointAnnotation alloc] init];
pa.coordinate = touchMapCoordinate;
pa.title = @"Circle Based Search";

[mapview addAnnotation:pa];
[pa release];

tmC = touchMapCoordinate;
double radius = 1000.0;

self.circleOverlay = [MKCircle circleWithCenterCoordinate:tmC radius:radius];
[mapview removeOverlays:[mapview overlays]];
[mapview addOverlay:circleOverlay]; …
Run Code Online (Sandbox Code Playgroud)

iphone mapkit mkmapview ios mkoverlay

8
推荐指数
1
解决办法
683
查看次数

平滑调整MKCircle的大小

在调整NSSlider时,如何在UIMapView上平滑调整MKCircleView的大小?苹果已经成功地做到这一点在查找好友创建地理围栏时,应用程序(http://reviewznow.com/wp-content/uploads/2013/03/find-my-friends-location-alerts-01.jpg),所以我想这在某种程度上是可能的.到目前为止,我已经尝试了以下解决方案,但结果非常"闪烁":

第一次尝试

我添加了一个具有更新半径的新MKCircleView,并在移除滑块更改值后立即移除(如此处建议MKOverlay不能平滑地调整大小).我也尝试过另一种方法:首先删除叠加层,然后添加一个新叠加层,但使用相同的"flickery"结果.

- (void)sliderChanged:(UISlider*)sender
{
    double radius = (sender.value * 100);
    [self addCircleWithRadius:radius];
    [mapView removeOverlays:[self.mapView.overlays firstObject]];
}
Run Code Online (Sandbox Code Playgroud)

第二次尝试

在链接的SO答案中,他建议NSOperation可用于"帮助您更快地创建MKCircle对象",从而在幻灯片更改值时使用上述添加/删除叠加层的方法使调整大小更加平滑.我做了一个实现,每当滑块改变时我就开始一个新的线程.在每个线程中,我删除所有旧的叠加层并添加一个新的叠加层.也许他还有其他一些实现方式,因为我这样做的方式在更改滑块时仍然会出现相同的闪烁.

- (void)sliderChanged:(UISlider*)sender
{
     NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
                                                                             selector:@selector(updateOverlayWithScale:)
                                                                               object:[NSNumber numberWithFloat:sender.scale]];
     [self.queue addOperation:operation];
}
Run Code Online (Sandbox Code Playgroud)

每个线程运行的方法:

- (void)updateOverlayWithScale:(NSNumber *)scale
{
    MKCircle *circle = [MKCircle circleWithCenterCoordinate:self.currentMapPin.coordinate
                                                     radius:100*[scale floatValue]];


    [self.mapView performSelectorOnMainThread:@selector(removeOverlays:) withObject:self.mapView.overlays waitUntilDone:NO];
    [self.mapView performSelectorOnMainThread:@selector(addOverlay:) withObject:circle waitUntilDone:NO];
}
Run Code Online (Sandbox Code Playgroud)

第三次尝试

我还尝试实现我自己的MKOverlayView子类,它根据scale属性绘制自己.每当滑块改变时,我调用setNeedsDisplay并让它自己重绘,但我得到相同的闪烁.

- (void)sliderChanged:(UISlider*)sender
{
     self.currentOverlayView.scale = sender.scale
     [self.currentOverlayView setNeedsDisplay];
}
Run Code Online (Sandbox Code Playgroud)

而在我的自定义重叠视图我实现drawMapRect:zoomScale:inContext的:(CGContextRef)背景下这样的

- (void)drawMapRect:(MKMapRect)mapRect
          zoomScale:(MKZoomScale)zoomScale
          inContext:(CGContextRef)context
{
     double …
Run Code Online (Sandbox Code Playgroud)

objective-c mapkit mkmapview ios mkoverlay

8
推荐指数
1
解决办法
2715
查看次数

如何从地址字符串中获取lat和long坐标

我有一个MKMapView,有一个UISearchBar在上面,我希望用户能够键入一个地址,并找到该地址并在其上放置一个图钉.我不知道的是如何将地址字符串转换为经度和纬度,所以我可以创建一个CLLocation对象.有谁知道我怎么做到这一点?

mapkit cllocation cllocationcoordinate2d

8
推荐指数
1
解决办法
1万
查看次数

如何使用故事板给出位置坐标以在ios中绘制地图中的点?

我正在使用storyboard在视图控制器中创建地图视图.

当我使用以下代码时.

-(void) mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    CLLocationDistance distance = 1000;   
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate,
                               distance, 
                               distance);
    MKCoordinateRegion adjusted_region = [self.mapView regionThatFits:region];
    [self.mapView setRegion:adjusted_region animated:YES];
}
Run Code Online (Sandbox Code Playgroud)

在美国加利福尼亚州旧金山绘制一个点.该 userLocation坐标是预定值MapKit.h框架.现在我创建一个

-(void) mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    CLLocationDistance distance = 1000;
    CLLocationCoordinate2D myCoordinate;
    myCoordinate.latitude = 13.04016;
    myCoordinate.longitude = 80.243044;
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(myCoordinate, 
                                                                   distance, 
                                                                   distance);
    MKCoordinateRegion adjusted_region = [self.mapView regionThatFits:region];
    [self.mapView setRegion:adjusted_region animated:YES];
}
Run Code Online (Sandbox Code Playgroud)

这里,显示具有中心坐标的区域.但是,在坐标位置没有绘制点.

如何在该坐标位置绘制点或注释?

mapkit ios cllocationcoordinate2d

8
推荐指数
1
解决办法
1万
查看次数

MKPolylineView initWithPolyLine:在iOS 7中已弃用

我收到以下错误:: initWithPolyline不推荐使用:首先在iOS 7.0中弃用

MKPolylineView *lineView = [[MKPolylineView alloc] 
       initWithPolyline:overlay];
Run Code Online (Sandbox Code Playgroud)

替代方法的替代方法是什么?

deprecated mapkit mkmapview ios mkpolyline

8
推荐指数
2
解决办法
3786
查看次数

向地图添加多个注释但是全部显示一些相同的数据

更新2:

这是映射中的现有代码,但它就像注释使用引脚完全无序.一次引脚为绿色,下次运行时,相同的引脚为红色.断开来自哪里?

-(void) viewWillAppear:(BOOL)animated {
    self.annotationArray = [[NSMutableArray alloc] init];

CLLocationCoordinate2D coord = {.latitude =  15.8700320, .longitude =  100.9925410};
MKCoordinateSpan span = {.latitudeDelta =  3, .longitudeDelta =  3};
MKCoordinateRegion region = {coord, span};
[mapViewUI setRegion:region];
    PFQuery *query = [PFQuery queryWithClassName:@"Share"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
                       self.mapViewData = objects;
                        for (int i=0;i<[objects count];i++)
            {
                // Question * q = [[Question alloc]init];

                PFObject * obj = [self.mapViewData objectAtIndex:i];
                NSLog(@"%@", obj);
                self.theObject = obj;

                NSString *string = obj[@"WhereAt"];


                NSArray …
Run Code Online (Sandbox Code Playgroud)

mapkit mkmapview mkannotation mkannotationview ios

8
推荐指数
1
解决办法
217
查看次数

MKMapView中心和放大

我在一个项目上使用MKMapView,并希望将地图置于坐标上并放大.就像谷歌地图有:

GMSCameraPosition.camera(withLatitude: -33.8683,
                                  longitude: 151.2086,
                                  zoom: 6)
Run Code Online (Sandbox Code Playgroud)

有没有Mapkit方法呢?

mapkit mkmapview ios swift

8
推荐指数
4
解决办法
1万
查看次数

Xcode - 调试视图层次结构

我正在尝试调试我的应用程序的视图层次结构,并在Xcode窗口的左侧窗格中显示一个小紫色方块(参见屏幕截图).

知道那个问题可能是什么吗?

Xcode  - 调试视图层次结构

debugging xcode uikit mapkit swift

8
推荐指数
1
解决办法
1791
查看次数