标签: mapkit

使用CLGeocoder重复地理编码后,kCLErrorDomain错误2

我的应用程序中有一个搜索栏,用户可以输入一个地址,它会产生地理编码结果.根据以下代码,结果将根据用户类型进行更新:

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
    ...
    if (self.geocoder.geocoding) [self.geocoder cancelGeocode];
    [self.geocoder geocodeAddressString:searchText completionHandler:^(NSArray *placemarks, NSError *error) {
        if (error != nil) {
            NSLog(@"ERROR during geocode: %@", error.description);
            return;
        }
        //update the view
    }];
}
Run Code Online (Sandbox Code Playgroud)

这适用于用户输入搜索字段的前几个字符.但是,在用户重复输入更多字符后,地理编码器开始出现以下错误(我知道这意味着网络存在问题):

ERROR during geocode: Error Domain=kCLErrorDomain Code=2 "The operation couldn’t be completed. (kCLErrorDomain error 2.)"
Run Code Online (Sandbox Code Playgroud)

在重新加载整个ViewController之前,地理编码器不会再次运行.为什么会发生这种情况,我该怎么做才能解决它?

iphone core-location mapkit ios clgeocoder

25
推荐指数
2
解决办法
2万
查看次数

以编程方式放大MKMapView

我正在使用MKMapViewiPhone应用程序内部.单击按钮时,缩放级别必须增加.这是我的第一个方法:

MKCoordinateRegion zoomIn = mapView.region;
zoomIn.span.latitudeDelta *= 0.5;
[mapView setRegion:zoomIn animated:YES];
Run Code Online (Sandbox Code Playgroud)

但是,这段代码没有效果,因为我没有更新longitudeDelta值.所以我添加了这一行:

zoomIn.span.longitudeDelta *= 0.5;
Run Code Online (Sandbox Code Playgroud)

现在它有效,但有时候.该latitudeDeltalongitudeDelta不以同样的方式改变,我的意思是,他们的价值是不成正比.不知道怎么解决这个问题?

iphone mapkit mkmapview

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

如何使用MKAnnotationView创建自定义"pin-drop"动画?

我有一个实例,MKMapView并希望使用自定义注释图标,而不是MKPinAnnotationView提供的标准图钉图标.所以,我已经设置了一个名为CustomMapAnnotation的MKAnnotationView的子类,并且重写-(void)drawRect:了绘制CGImage.这有效.

当我尝试复制.animatesDropMKPinAnnotationView提供的功能时出现问题; 当注释被添加到MKMapView实例时,我希望我的图标能够逐渐显示,从上到下以及从左到右顺序显示.

这是 - (void)drawRect:用于CustomMapAnnotation,当你只绘制UIImage(这是第二行所做的)时它可以工作:

- (void)drawRect:(CGRect)rect {
 [super drawRect:rect];
 [((Incident *)self.annotation).smallIcon drawInRect:rect];
 if (newAnnotation) {
  [self animateDrop];
  newAnnotation = NO;
 }
} 
Run Code Online (Sandbox Code Playgroud)

添加animateDrop方法时出现问题:

-(void)animateDrop {
 CGContextRef myContext = UIGraphicsGetCurrentContext();

 CGPoint finalPos = self.center;
 CGPoint startPos = CGPointMake(self.center.x, self.center.y-480.0);
 self.layer.position = startPos;

 CABasicAnimation *theAnimation;
 theAnimation=[CABasicAnimation animationWithKeyPath:@"position"];
 theAnimation.fromValue=[NSValue valueWithCGPoint:startPos];
 theAnimation.toValue=[NSValue valueWithCGPoint:finalPos];
 theAnimation.removedOnCompletion = NO;
 theAnimation.fillMode = kCAFillModeForwards;
 theAnimation.delegate = self;
 theAnimation.beginTime = 5.0 * (self.center.x/320.0);
 theAnimation.duration = 1.0;
 [self.layer addAnimation:theAnimation …
Run Code Online (Sandbox Code Playgroud)

iphone core-animation mapkit mkpinannotationview

24
推荐指数
4
解决办法
3万
查看次数

我怎么知道MKMapview setRegion:animated:什么时候完成了?

我想在我的MKMapView上设置一个区域,然后找到与地图的NE和SW角对应的坐标.

This code works just fine to do that:
//Recenter and zoom map in on search location
MKCoordinateRegion region =  {{0.0f, 0.0f}, {0.0f, 0.0f}};
region.center = mySearchLocation.searchLocation.coordinate;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[self.mapView setRegion:region animated:NO]; //When this is set to YES it seems to break the coordinate calculation because the map is in motion

//After the new search location has been added to the map, and the map zoomed, we need to update the search bounds
//First we need …
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch mapkit mkmapview

24
推荐指数
2
解决办法
9746
查看次数

如果我不再使用MKMapView,为什么我会崩溃?

我有一个MKMapView.有时在我的视图控制器被解雇后,我会得到一个EXC_BAD_ACCESS.

我打开了NSSZombies,它看起来像是MKMapView代表 - 我的视图控制器!- 正在被调用,尽管释放了子类MKMapViewUIViewController子类.我已经检查了,我的记忆管理是正确的.

这是怎么回事?

iphone memory-management mapkit mkmapview

24
推荐指数
2
解决办法
4967
查看次数

我想从MapKit for iPhone中的Coordinate值获取Location名称

我想从坐标值中获取位置名称.这是代码,

- (void)viewWillAppear:(BOOL)animated {  
    CLLocationCoordinate2D zoomLocation;
    zoomLocation.latitude = 39.281516;
    zoomLocation.longitude= -76.580806;
    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 0.5*METERS_PER_MILE, 0.5*METERS_PER_MILE);
    MKCoordinateRegion adjustedRegion = [_mapView regionThatFits:viewRegion];                
    [_mapView setRegion:adjustedRegion animated:YES];      
}
Run Code Online (Sandbox Code Playgroud)

所以,从纬度和经度来看,我想知道位置名称.

iphone xcode mapkit ios5

24
推荐指数
2
解决办法
3万
查看次数

带按钮的自定义MKAnnotation标注气泡

我正在开发应用程序,用户通过gps进行本地化,然后询问他是否位于特定位置.为了证实这一点,他会立即向他提出标注泡沫,询问他是否在特定的地方.

由于有很多类似的问题,我能够做自定义标注泡泡: 自定义标注泡泡

我的问题:按钮不是"可点击"我的猜测:因为这个自定义标注高于标准标注泡泡,我不得不将它放在负"框架"中,因此无法点击按钮.这是我的didSelectAnnotationView方法

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
    if(![view.annotation isKindOfClass:[MKUserLocation class]]) {
        CalloutView *calloutView = (CalloutView *)[[[NSBundle mainBundle] loadNibNamed:@"callOutView" owner:self options:nil] objectAtIndex:0];
        CGRect calloutViewFrame = calloutView.frame;
        calloutViewFrame.origin = CGPointMake(-calloutViewFrame.size.width/2 + 15, -calloutViewFrame.size.height);
        calloutView.frame = calloutViewFrame;
        [calloutView.calloutLabel setText:[(MyLocation*)[view annotation] title]];
        [calloutView.btnYes addTarget:self
                               action:@selector(checkin)
                     forControlEvents:UIControlEventTouchUpInside];
        calloutView.userInteractionEnabled = YES;
        view.userInteractionEnabled = YES;
        [view addSubview:calloutView];
    }

}
Run Code Online (Sandbox Code Playgroud)

CalloutView只是简单的类,有2个属性(标签显示地方名称和按钮)和xib.

我一直在做这个自定义标注泡泡几天.我尝试使用"异步解决方案" 解决方案,但我无法添加任何其他类型的按钮然后披露按钮.

我的下一次尝试是找到比异步解决方案更容易的东西并将其修改为我的用途.多数民众赞成我如何找到tochi的自定义标注.

Tochi的自定义标注

基于他的工作,我能够自定义他的泡泡并更改我的自定义按钮的信息按钮.然而,我的问题仍然存在.为了将我的自定义标注视图放在引脚顶部,我不得不给它负帧,所以我的按钮只能在底部5个像素中"可点击".看来,我必须深入挖掘ios默认的标注气泡,将其子类化并在那里更改标注框架.但我现在真的很无望.

如果你们能告诉我正确的方法,或者给我建议,我会很高兴的.

frame mapkit ios callout

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

在iOS7中检测MKOverlay上的触摸(MKOverlayRenderer)

我有一个可能有数百个多边形的MKMapView.iOS7上假设使用MKPolygon和MKPolygonRenderer.

我需要的是一种对用户触摸其中一个多边形的方式.它们代表地图上具有一定人口密度的区域.在iOS6上,MKOverlay被绘制为MKOverlayViews,因此触摸检测更直接.现在使用渲染器我真的不明白这是怎么做的.

我不确定这会有所帮助甚至是相关的,但作为参考,我会发布一些代码:

这会使用mapData将所有MKOverlay添加到MKMapView.

-(void)drawPolygons{
    self.polygonsInfo = [NSMutableDictionary dictionary];
    NSArray *polygons = [self.mapData valueForKeyPath:@"polygons"];

    for(NSDictionary *polygonInfo in polygons){
        NSArray *polygonPoints = [polygonInfo objectForKey:@"boundary"];
        int numberOfPoints = [polygonPoints count];

        CLLocationCoordinate2D *coordinates = malloc(numberOfPoints * sizeof(CLLocationCoordinate2D));
        for (int i = 0; i < numberOfPoints; i++){
            NSDictionary *pointInfo = [polygonPoints objectAtIndex:i];

            CLLocationCoordinate2D point;
            point.latitude = [[pointInfo objectForKey:@"lat"] floatValue];
            point.longitude = [[pointInfo objectForKey:@"long"] floatValue];

            coordinates[i] = point;
        }

        MKPolygon *polygon = [MKPolygon polygonWithCoordinates:coordinates count:numberOfPoints];
        polygon.title = [polygonInfo objectForKey:@"name"];
        free(coordinates);
        [self.mapView addOverlay:polygon];
        [self.polygonsInfo setObject:polygonInfo forKey:polygon.title]; …
Run Code Online (Sandbox Code Playgroud)

touch mapkit mkmapview ios mkoverlay

24
推荐指数
3
解决办法
7309
查看次数

在Swift游乐场中使用MapKit显示地图以便快速查看?

很高兴看到swift-playground的标签 - 喜欢看到这种情况继续下去.

我一直在修补Swift,我想知道MapKit是否可以在操场上使用,这样你就可以使用Quick Look功能,这样我就可以迭代并使用我的工作预览.我还没想出语法,所以我想问一下是否有人在游乐场环境中探讨过这个问题.我想我需要一些代码来建立它作为一个视图控制器.

import UIKit
import MapKit

// Sample UIView code which works great in the playground.
//var myView:UIView = UIView();
//myView.frame = CGRectMake(0, 0, 320, 560)
//myView.backgroundColor = UIColor.blueColor()

// Non working map code - no errors but can't figure out what to call or initiate to get the view in the Quick Look side.

var mapView = MKMapView();
mapView.region.center.latitude = mapView.userLocation.coordinate.latitude;
mapView.region.center.longitude = mapView.userLocation.coordinate.longitude;
mapView.region.span.latitudeDelta = 0.00725;
mapView.region.span.longitudeDelta = 0.00725;
Run Code Online (Sandbox Code Playgroud)

猜测我只是缺少一些简单的mapView来初始化自己等等.我喜欢解释的游乐场区域进行修补,只需要弄清楚它是否可以做mao功能而不是仅仅在Xcode中编写.swift文件和环境并获取更正式.

mapkit swift swift-playground

24
推荐指数
2
解决办法
8991
查看次数

使用MapKit将Swins添加到Map中 - Swift 3.0

新编码器,试图弄清楚如何使用MapKit.目标是创建一个地图,用户可以使用他们的地址添加引脚.但是,我现在的步骤,我很难搞清楚如何将地图添加到地图.

如何在地图上添加图钉?到目前为止,我一直在努力弄清楚如何使用注释.

这就是我希望得到帮助/指导的方式.谢谢!

import UIKit
import MapKit
import CoreLocation

class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate

{
    @IBOutlet weak var bigMap: MKMapView!

    let locationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()
        self.locationManager.delegate = self
        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
        self.locationManager.requestWhenInUseAuthorization()
        self.locationManager.startUpdatingLocation()
        self.bigMap.showsUserLocation = true

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        let location = locations.last
        let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
        let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.02, longitudeDelta: 0.02))

        self.bigMap.setRegion(region, animated: true)
        self.locationManager.stopUpdatingLocation() …
Run Code Online (Sandbox Code Playgroud)

mapkit ios mapkitannotation swift

24
推荐指数
2
解决办法
4万
查看次数