我有这个代码来设置用户位置的地图:
MKCoordinateSpan span;
span.latitudeDelta=0.2;
span.longitudeDelta=0.2;
CLLocationCoordinate2D location=mapView.userLocation.coordinate;
location = mapView.userLocation.location.coordinate;
MKCoordinateRegion region;
region.span=span;
region.center=location;
[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
Run Code Online (Sandbox Code Playgroud)
现在,当我这样做时,mapView.showsUserLocation=YES它显示我在正确位置的位置(在我的设备上,以及模拟器中的苹果公司),但是,上面的代码两次都把我放在非洲附近的某个海域!
有任何想法吗?
有人知道如何将可访问性标签添加到地图注释中吗?我已经尝试将它添加到MKAnnotationView和MKAnnotation但是都不起作用.选择注释时,VoiceOver始终只读取"pin",而原始地图应用程序在选择注释时会显示正确的标题.
谢谢和最好的问候,
克里斯
我有一个CLLocation从文件中解析的对象数组.我想模拟用户沿着那条路线移动,我已经实现了这个:
for (CLLocation *loc in simulatedLocs) {
[self moveUser:loc];
sleep(1);
}
Run Code Online (Sandbox Code Playgroud)
这是循环中调用的方法:
- (void)moveUser:(CLLocation*)newLoc
{
CLLocationCoordinate2D coords;
coords.latitude = newLoc.coordinate.latitude;
coords.longitude = newLoc.coordinate.longitude;
CustomAnnotation *annotation = [[CustomAnnotation alloc] initWithCoordinate:coords];
annotation.title = @"User";
// To remove the previous location icon
NSArray *existingpoints = self.mapView.annotations;
if ([existingpoints count] > 0) {
for (CustomAnnotation *annotation in existingpoints) {
if ([annotation.title isEqualToString:@"User"]) {
[self.mapView removeAnnotation:annotation];
break;
}
}
}
MKCoordinateRegion region = { coords, {0.1, 0.1} };
[self.mapView setRegion:region animated:NO];
[self.mapView addAnnotation: …Run Code Online (Sandbox Code Playgroud) 我正在开发一个小项目,在地图上显示7种不同类型的注释.我的注释取自数组中的url结果,我使用JSON解析它.我有很多注释,一旦地图加载,一切看起来都很好.放大和缩小后,引脚图像由于某种原因改变为错误的引脚图像(特定图像,没有线索原因).
我相信我在这里遗失了一些东西......请你帮忙:)?
这是我的代码的一部分,如果您需要它,请告诉我:
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
static NSString *identifier;
if(_mapView.tag==1){identifier = @"TurbulencePin";}
if(_mapView.tag==2){identifier = @"IcingPin";}
if(_mapView.tag==3){identifier = @"WindsPin";}
if(_mapView.tag==4){identifier = @"TemperaturePin";}
if(_mapView.tag==5){identifier = @"CloudsPin";}
if(_mapView.tag==6){identifier = @"VisibilityPin";}
if(_mapView.tag==7){identifier = @"MultiplePin";}
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
if ([annotation isKindOfClass:[Annotation class]]) {
CustomAnnotationView* annotationView = (CustomAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
annotationView = nil;
if (annotationView == nil) {
annotationView = [[CustomAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"%@.png",identifier]];
annotationView.image = img;
}
else
{
annotationView.annotation …Run Code Online (Sandbox Code Playgroud) 我有一个带导航控制器和标签栏控制器的ViewController.此ViewController有2个按钮,用于切换滚动视图和地图视图的可见性.最重要的是让这两个按钮始终显示在同一个地方,无论方向或恰好可见的视图.
我遇到的问题是MapView的大小不正确.如果我只是从self.view.bounds给它一个框架它位于导航栏/标签栏下 - 基本上占据了整个屏幕.这会抛弃我的切换按钮的位置.
我注意到我的ScrollView也是这样(使用背景颜色和半透明导航栏),但子视图在其上的位置保持在可见区域内(导航栏和标签栏之间).因此,当我添加切换按钮时,它们会显示在正确的位置.
当我按下切换按钮时,我只是将按钮的父视图重新分配给现在显示的视图(ScrollView或MapView).这总是适用于滚动视图,但由于定位,它们最终会在显示MapView时进入导航栏下方.
我已经尝试手动创建MapView的框架,但我得到奇怪的结果.我用它作为框架:
CGRect mapFrame = CGRectMake(
0,
(self.navigationController.navigationBar.frame.size.height + [UIApplication sharedApplication].statusBarFrame.size.height),
self.view.frame.size.width,
(
self.view.frame.size.height
- (self.navigationController.navigationBar.frame.size.height + [UIApplication sharedApplication].statusBarFrame.size.height + self.tabBarController.tabBar.frame.size.height)
)
);
Run Code Online (Sandbox Code Playgroud)
然后我设置自动调整大小的面具
[self.mapView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin];
Run Code Online (Sandbox Code Playgroud)
但有了这个,如果我以横向模式进入视图控制器 - MapView不在屏幕上.如果我进入纵向模式然后旋转到横向,则上边距关闭但大约10个点,因此它仍然位于导航栏下方(并且在标签栏和地图视图底部之间有可见边距).
如何使MapView子视图仅显示在可见区域内,就像ScrollView一样?如果地图本身位于导航栏/标签栏下方,我不介意
我正在使用MKMapView在iOS模拟器中获得看起来随机发生的崩溃.它不是由任何用户操作触发的,它只是无中生有.我得到以下堆栈跟踪:
<_NSCallStackArray 0x2d9762b0>(
0 ??? 0x137d69bd 0x0 + 326986173,
1 Foundation 0x03ca3b0a -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 282,
2 Foundation 0x03c10b61 _NSGetUsingKeyValueGetter + 81,
3 Foundation 0x03c1019b -[NSObject(NSKeyValueCoding) valueForKey:] + 260,
4 AccessibilityUtilities 0x11ad1a3f -[NSObject(UIAccessibilitySafeCategory) safeValueForKey:] + 43,
5 MapKitFramework 0x12090aa4 -[MKBasicMapViewAccessibility(SafeCategory) accessibilityContainerElements] + 91,
6 UIAccessibility 0x11fc7149 -[NSObject(AXPrivCategory) accessibilityElementCount] + 34,
7 UIAccessibility 0x11fc751f -[NSObject(AXPrivCategory) _accessibilityHasOrderedChildren] + 59,
8 UIKit 0x11ebb388 -[UIViewAccessibility(SafeCategory) _accessibilitySubviewsForGettingElementsIncludingContainers:includingOpaqueElementProviders:] + 2269,
9 UIKit 0x11ebba96 -[UIViewAccessibility(SafeCategory) _accessibilityElementsInContainer:topLevel:includeKB:includeOpaqueElementProviders:] + 486,
10 UIKit 0x11eba12f -[UIViewAccessibility(SafeCategory) _accessibilityElementsInContainer:topLevel:includeKB:] + 64,
11 UIKit …Run Code Online (Sandbox Code Playgroud) 我正在开发这样一个应用程序执行以下操作的项目:
viewController按"开始"按钮转到下一个现在,我在这里监视一个区域,然后再监视另一个区域.所以数字实际上就是一个.但是我知道一个应用程序可以通过"区域监控"监控的区域的最大数量是15.现在我的问题是在这种情况下我应该处理这个最大数量的区域问题吗?如果是,那怎么样?
我想补充的另一件事是,它有一些解决方案,它只适用于iOS 6及更早版本.所以请根据用户在iOS7中的当前位置,通过"RegionMonitoring"监控处理"区域"数量的解决方案,让我知道.
如果能够给出答案或任何建议来完成我的应用程序所需要求,我将感到非常高兴.
我正在使用此代码来设置一个区域MKMapView,使其居中pin并缩放以显示大约10km的区域.
CLLocationAccuracy accuracy = kCLLocationAccuracyKilometer;
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(pin.coordinate, accuracy * 10.0f, accuracy * 10.0f);
[self.mapSubView setRegion:region animated:NO];
Run Code Online (Sandbox Code Playgroud)
运行纬度-90,经度-58.359001159667969的引脚坐标的代码时,region生成如下所示:

mapSubView绘制时发生崩溃: -
因未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'无效区域<center:-90.00000000,-58.35900116 span:+0.08953039,+ 1462142065660629.00000000>'
我第一次尝试解决此问题是检查"边缘"纬度/长度(-90,+ 90,-180,+ 180),这解决了这个问题.但是,如果纬度更改为-89.99999,则问题将返回.
我猜这是由于纬度存在的组合-90和/或区域跨度的经度三角洲是如此之大,导致在实际上是"这个世界的"一区:P
任何关于如何在任何坐标处围绕销钉居中的建议,显示~10km的区域,没有这种碰撞将是非常感谢.
当我尝试符合MKAnnotation协议时,它会抛出错误,我的类不符合协议MKAnnotation.我使用以下代码
import MapKit
import Foundation
class MyAnnotation: NSObject, MKAnnotation
{
}
Run Code Online (Sandbox Code Playgroud)
Objective-C也可以做同样的事情.
MKMapView提供了几种方法,可以让您设置可见地图rect(或区域,坐标范围等).这些方法具有动画参数,当设置为true时,使用大约0.3秒的线性动画来为变化设置动画.
虽然这很好,但我想复制Apple 在点击地图时在他的" 查找我的朋友"和" 查找我的iPhone"应用程序中使用的动画.如果你自己尝试一下,你会发现一个非线性曲线的动画要快得多(大约0.15秒).现在,我们称之为"反弹 - 缩放"过渡.
我想要复制非线性动画曲线和自定义动画持续时间.在UIView的animateWithSpring ...方法中包装地图更新似乎不起作用(我当然可能做错了).非常清楚Apple可能有能力做MKMapView API中没有公开的东西,但Apple的App Store分布式应用程序通常似乎坚持他们关于公共API的指导方针.
这可能吗?如果是这样 - 怎么样?仅仅改变动画持续时间并不是我追求的.我也想控制动画曲线.
在这里看到一个试图做上述操场的游乐场.请注意,MKMapView似乎考虑了动画持续时间,但不考虑弹性,例如Find my iPhone/Find my Friends.
mapkit ×10
ios ×8
mkmapview ×5
iphone ×3
objective-c ×2
swift ×2
annotations ×1
geofencing ×1
ios5 ×1
mkannotation ×1
voiceover ×1