Tag: mapkit

从plist加载时基于MapKit的应用程序崩溃

我正在编写一个程序,它使用MapKit来显示一个地图,它将从plist文件中加载自定义的注释。 每个注释都是根数组中的字典项目,带有标题,副标题,纬度和经度。 当我为了testing目的对注释进行硬编码时,程序运行的很好。 但是,随着MapDemoAnnotation类的添加以及我尝试读取属性列表,程序在启动时崩溃。 这是我的注释实现: #import "MapDemoAnnotation.h" @implementation MapDemoAnnotation @synthesize coordinate; @synthesize title; @synthesize subtitle; -(id)initWithDictionary:(NSDictionary *)dict{ self = [super init]; if(self!=nil){ coordinate.latitude = [[dict objectForKey:@"latitude"] doubleValue]; coordinate.longitude = [[dict objectForKey:@"longitude"] doubleValue]; self.title = [dict objectForKey:@"name"]; self.subtitle = [dict objectForKey:@"desc"]; } return self; } -(void)dealloc{ [title release]; [subtitle release]; [super dealloc]; } @end 我猜我的RootViewController类中的viewDidLoad方法是问题,但。 – […]

Swift – 将圆angular设置为注释视图图像

这是我以前的线程,我把图像设置为注释视图引脚 Swift – 将arrays中的不同图像设置为注释引脚 现在我遇到了在注解视图图像上设置圆angular的问题。 cannot show callout with clipsToBounds enabled swift 似乎我必须select圆angular或显示标注,我真的不明白为什么这两个不能来。 有没有办法做到这一点? 这里是我的viewForAnnotation函数: func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! { if !(annotation is RestaurantAnnotation) { return nil } let reuseId = "restaurant" var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) if anView == nil { anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId) anView.canShowCallout = false } […]

启用和禁用注释拖动(即时)(iOS Mapkit)

我创build了一个mapview,它有一个button,可以根据项目需求在“编辑”模式和“拖动”模式之间切换。 我意识到通过在viewForAnnotation中设置它们可拖动的方式可以使拖动的注释变得容易,但是所需的行为不允许这样做。 我尝试了几种不同的方式来将注释更改为可拖动而没有成功。 首先想到的是循环现有的注释,并设置每个“可拖动”和“选定”,但我得到一个无法识别的select发送到实例错误(我尝试实例化一个新的注释传入的对象和重绘而在循环中,但我也得到相同的错误): NSLog(@"Array Size: %@", [NSString stringWithFormat:@"%i", [mapView.annotations count]]); for(int index = 0; index < [mapView.annotations count]; index++) { if([[mapView.annotations objectAtIndex:index]isKindOfClass:[locAnno class]]){ NSLog(@"** Location Annotation at Index: %@", [NSString stringWithFormat:@"%i", index]); NSLog(@"* Location Marker: %@", [mapView.annotations objectAtIndex:index]); } if([[mapView.annotations objectAtIndex:index]isKindOfClass:[hydAnno class]]) { NSLog(@"** Hydrant Annotation at Index: %@", [NSString stringWithFormat:@"%i", index]); NSLog(@"* Hydrant […]

折线不从用户位置绘制(蓝点)

– (void)viewDidLoad { [super viewDidLoad]; CLLocationCoordinate2D currentLocation; currentLocation.latitude = self.mapView.userLocation.location.coordinate.latitude; currentLocation.longitude = self.mapView.userLocation.location.coordinate.longitude; CLLocationCoordinate2D otherLocation; otherLocation.latitude = [lati doubleValue]; otherLocation.longitude = [longi doubleValue]; MKPointAnnotation *mka = [[MKPointAnnotation alloc]init]; mka.Coordinate = otherLocation; mka.title = @"!"; [self.mapView addAnnotation:mka]; self.mapView.delegate = self; MKMapPoint *pointsArray = malloc(sizeof(CLLocationCoordinate2D)); pointsArray[0]= MKMapPointForCoordinate(currentLocation); pointsArray[1]= MKMapPointForCoordinate(otherLocation); routeLine = [MKPolyline polylineWithPoints:pointsArray count:2]; free(pointsArray); [self.mapView addOverlay:routeLine]; […]

iOS:(Swift)如何显示当前位置的距离,并在注解字幕上存在注释

我目前正在使用Swift语言在iOS上开发地图应用程序。 我想build议,因为我在地图视图上绘制所有的针脚后 (我使用JSON框架从我的服务器接收数据,调用Alamofire) 我想在地图上的所有注释的副标题显示距用户当前位置的距离。 现在它可以在地图视图上添加注释,但只能根据从我的服务器接收的信息显示标题和字幕。 谢谢。

无法将MapKit用户坐标转换为屏幕坐标

这其实是一个线程中三个不同的问题: 1)我正在使用: – (void)viewDidLoad { [super viewDidLoad]; [mapView setFrame :CGRectMake(-100,-100,520,520)]; [mapView setAutoresizesSubviews:true]; mapView.showsUserLocation = YES; locManager = [[CLLocationManager alloc] init]; locManager.delegate = self; [locManager startUpdatingLocation]; [locManager startUpdatingHeading]; [bt_toolbar setEnabled:YES]; } – (IBAction) CreatePicture { CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(mapView.userLocation.coordinate.latitude, mapView.userLocation.coordinate.longitude); CGPoint annPoint = [self.mapView convertCoordinate:coord toPointToView:self.mapView]; mapPic = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pic.png"]]; mapPic.frame = CGRectMake(annPoint.x, annPoint.y, […]

如何在iOS 6地图上绘制路线?

我想在地图上显示地图和绘制路线。 我的应用程序支持ios 4 plus。 那么我应该如何使用地图来处理iOS 6以及之前的工作。 此外,我想知道sholud我使用自定义mapview在我的应用程序来显示地图和路线,或者我应该使用 [[UIApplication sharedApplication] openURL:] 我从来没有用户的MapKits 。 所以请提供任何教程。 也让我知道是否有任何可用的党的图书馆。

在iOS6中为MKMapKit路由数据

我之前已经在iOS应用程序中完成了路由,但是在iOS6中,我们现在正在显示Apple地图 – 这会导致问题,因为我们正在使用Google路由数据,如果使用Google数据,我们应该将其显示在Google地图上。 我一直在寻找,但据我所知,苹果公司并没有提供任何路由数据。 到目前为止,答案最接近的东西似乎是苹果公司表示Apps that consume direction information do so by sending an appropriate request to the Maps app, which then handles the task of displaying that information to the user. – 对我来说,这意味着地图应用程序将被打开以显示路线,并将用户带出我们的应用程序。 我们在哪里可以获得在iOS6应用程序上使用苹果地图可以接受的即时路线数据?

具有自定义视图和图像视图的MKAnnotationView

在我的地图应用程序,而不是显示一个别针,我想显示一个彩色的背景圆形图像。 背景的颜色(下面的图像是绿色的阴影)是dynamic的。 它将如下图所示: 我创build了TCircleView在“drawRect”中绘制颜色 为了显示类似的注释,我创build了TCircleView和UIImageView的对象,并将它们添加到MKAnnotationView对象中。 它看起来不错,如预期般可见。 但它不允许检测点击/触摸来显示呼叫。 我使用下面的代码: – (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation { if ([annotation isKindOfClass:[MKPointAnnotation class]]) { return nil; } static NSString *annotationIdentifier = @"StickerPin"; MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier]; if (!annotationView) { annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationIdentifier]; annotationView.canShowCallout = YES; } TCircleView* circleView = [[TCircleView alloc] init]; circleView.green = [postObj[@"severity"] […]

使用CLLocation计算距离iOS MapKit

我正在尝试使用经度和纬度查找以英里为单位的距离。 我有以下的方法: – (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { if(!newLocation) return; if ((oldLocation.coordinate.latitude != newLocation.coordinate.latitude) && (oldLocation.coordinate.longitude != newLocation.coordinate.longitude)) { CLLocation *loc1 = [[CLLocation alloc] initWithLatitude:oldLocation.coordinate.latitude longitude:oldLocation.coordinate.longitude]; CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.latitude]; CLLocationDistance distance = ([loc2 distanceFromLocation:loc1]) * 0.000621371192; //distance = distance; NSLog(@"Total Distance %f in miles",distance); } } 出于某种原因,它打印出5678.32英里的东西。 位置非常静止,根本不移动。