问候!我试图在没有任何Apple代码示例的情况下使用MKMapView,尽管还有其他一些不同的清晰度.(我知道,"阅读友好的手册."我已经做到了,但并非100%明确,所以请耐心等待.)
这是情况.我有一个MKMapView对象,其中我添加了一组大约十个MKPinAnnotation对象.到现在为止还挺好.一切都得到了很好的分配/释放,似乎没有任何来自仪器的投诉.
在初始显示时,我设置了一个MKCoordinateRegion对象,其中心点位于我们的第一个引脚位置,并且(任意)跨度为0.2 x 0.2.然后我打电话给:
[mapView setRegion:region animated:YES];
[mapView regionThatFits:region];
Run Code Online (Sandbox Code Playgroud)
哇!这很好用.
同时......我还有一个分段控制,允许移动到每个引脚位置.因此,当我点击列表时,地图会动画到每个新的引脚位置,并使用一对新的setRegion:animated:和regionThatFits: ...或者至少是这个想法.
当地图"移动"到新的引脚位置时,地图本身不会在下面更新.相反,我看到我的图钉在灰色/空白地图背景上... 直到我向任何方向轻推地图,不过有点轻微.然后地图显示通过!(如果我只是在前一个引脚位置的一小段距离内移动,我通常会看到地图的任何部分已经加载了.)
我怀疑我在这里做了一些愚蠢的事,但我无法弄清楚什么,至少不是来自MapKit文档.也许我正在使用错误的电话?(好吧,我确实需要设置该区域至少一次,是吗?移动它似乎没有帮助.)我也尝试过使用setCenterCoordinate:animated: - 同样的问题.
我现在什么都不做(没有双关语).只是想找到自己的方式.
线索欢迎/赞赏!
更新:调用setRegion:animated:和regionThatFits:第一次,然后是setCenterCoordinate:animated:在遍历列表时,没有任何效果.有趣的发现:如果我在两种情况下都将动画更改为NO,则地图会更新!!! 只有当它设置为YES时.(什么时候发生?!动画:破碎了?那不可能...... ???)
如何找到被点击的引脚的引脚ID(即引脚标题和副标题的详细信息)?
我有这个来显示引脚注释.这段代码在视图中加载:
[resultCoordinate addObjectsFromArray:[sqlClass return_Coordinate]];
if ([resultCoordinate count])
{
for (int i =0; i < [resultCoordinate count]; i++)
{
dict = [resultCoordinate objectAtIndex:i];
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = [[dict objectForKey:@"Lati"] floatValue];
region.center.longitude = [[dict objectForKey:@"Longi"] floatValue];
region.span.longitudeDelta = 0.2f;
region.span.latitudeDelta = 0.2f;
NSString *fishName = [dict objectForKey:@"Fish"];
fishName = [fishName stringByAppendingString:@" "];
NSString *fishWeight = [dict objectForKey:@"Weight"];
fishWeight = [fishWeight stringByAppendingString:@" kg"];
fishName = [fishName stringByAppendingString:fishWeight];
MapAnnotation *ann = [[MapAnnotation alloc] …Run Code Online (Sandbox Code Playgroud) 有没有办法在Xcode 4上设置iPhone模拟器中的当前用户位置?我希望模拟器显示除Cupertino之外的其他位置.
在我的应用程序中,我注意到当我按下并弹出一个包含MKMapView内存的视图控制器时,内存使用量会稳步增加.我已经确定MapKit本身存在问题,而不是我的代码.我做了一个测试项目,其中只包含一个导航控制器,我可以反复推送和弹出一个只包含地图视图的视图控制器 - 没有注释或叠加.当我一遍又一遍地推动和弹出视图控制器时,每个推/弹循环的内存使用量增加约0.6 MB.有关为什么会发生这种情况的任何想法?我正在使用ARC.谢谢!
编辑:
我在iOS 5.1模拟器中做了一些测试(我知道在模拟器中有关于性能分析的问题,但我没有任何可用于测试的iOS 5设备),我的结果表明这是一个错误iOS 6; 在iOS 6模拟器中,我看到内存使用量逐渐增加,但在iOS 5模拟器中,内存使用率没有上升.我认为这是Apple新的内部地图的问题.
我正在使用mapkit 为iOS 6制作应用程序.我想将地图的边界限制在特定的地区/国家.有没有办法做到这一点?
这里已经讨论过这个问题了: 如何将地图区域限制在iOS中只有一个国家/地区? 唯一的区别是可能的解决方案是针对ios 5.
我有一个半径和一个位置.
这就是我试图获得圆的边界矩形的方式.
- (MKMapRect)boundingMapRect{
CLLocationCoordinate2D tmp;
MKCoordinateSpan radiusSpan = MKCoordinateRegionMakeWithDistance(self.coordinate, 0, self.radius).span;
tmp.latitude = self.coordinate.latitude - radiusSpan.longitudeDelta;
tmp.longitude = self.coordinate.longitude - radiusSpanSpan.longitudeDelta;
MKMapPoint upperLeft = MKMapPointForCoordinate(tmp);
MKMapRect bounds = MKMapRectMake(upperLeft.x, upperLeft.y, self.radius * 2, self.radius * 2);
return bounds;
}
Run Code Online (Sandbox Code Playgroud)
MKMapRectMake(...)似乎想要在地图点测量宽度和高度.如何将半径转换为?
最后我将它呈现如下:
MKMapRect theMapRect = [self.overlay boundingMapRect];
CGRect theRect = [self rectForMapRect:theMapRect];
CGContextAddEllipseInRect(ctx, theRect);
CGContextFillPath(ctx);
Run Code Online (Sandbox Code Playgroud)
半径在地图上似乎最终不等于米,并且似乎也没有正确测量距离.怎么做对了?
我会非常感谢每一个提示.
我正在尝试找到一种方法来检测何时MKUserTrackingBarButtonItem使用,而不是处理mapView:didUpdateUserLocation:委托方法.
我尝试setAction MKUserTrackingBarButtonItem来调用我的函数(检查这个线程),但是诅咒它会删除更新位置操作,这是我不想要的.
我没有找到任何触发的委托方法:/
谢谢你的想法.
我有一个MapView集群注释(ADMapCluster).I want to show the amount of elements in the Cluster因此我将一个UILabel添加到MKAnnotationView作为子视图.
我的问题是,当我在缩放或类似操作后重用MKAnnotationView时,UILabel不会更新文本.
- (MKAnnotationView *)mapView:(ADClusterMapView *)mapView viewForClusterAnnotation:(id<MKAnnotation>)annotation {
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
MKAnnotationView * pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"ADMapCluster"];
if (!pinView) {
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"ADMapCluster"];
pinView.image = [UIImage imageNamed:@"map-markers"];
UILabel *countLabel = [[UILabel alloc] initWithFrame:CGRectMake(2, 5, 25, 20)];
countLabel.textAlignment = NSTextAlignmentCenter;
[countLabel setTag:2];
countLabel.text = [NSString stringWithFormat:@"%d",[[(ADClusterAnnotation*)pinView.annotation originalAnnotations] count] ];
countLabel.font = [UIFont fontWithName:@"Avenir-Book" size:10];
[pinView addSubview:countLabel];
}
else …Run Code Online (Sandbox Code Playgroud) 我有一个平面图或室内地图.我需要在具有基本地图功能的UI上表示此地图.我实际上想使用MapKit,但最大缩放级别不足以查看该图像.Google地图和Mapbox也存在同样的问题.
我试过叠加,但缩放级别是同样的问题,如果我根据lat-lon设置图像,地图上的重叠图像非常小.另一种解决方案是将图像/地图设置为任意纬度并在地图上使其更大,但这在图像外部(室内地图)看起来非常奇怪,默认地图视图是可见的.
我从UIScrollView开始,但是完成这些地图功能还有很长的路要走,是否有任何第三方库来解决我的问题.
我的目标是在视图上表示室内地图或平面图,该视图将提供所有基本地图功能(缩放,旋转,距离测量,丢弃图片等).
谢谢.
我正在尝试使用MKSnapshotter拍摄我的应用程序中固定位置的街景视图.我目前有这个代码:
var options: MKMapSnapshotOptions = MKMapSnapshotOptions();
options.region = self.attractionDetailMap.region;
options.size = self.attractionDetailMap.frame.size;
options.scale = UIScreen.mainScreen().scale;
var fileURL:NSURL = NSURL(fileURLWithPath: "path/to/snapshot.png")!;
var snapshotter:MKMapSnapshotter = MKMapSnapshotter();
snapshotter.startWithCompletionHandler { (snapshot:MKMapSnapshot!, error:NSError!) -> Void in
if(error != nil) {
println("error: " + error.localizedDescription);
return;
}
let image:UIImage = snapshot.image;
var data:NSData = UIImagePNGRepresentation(image);
data.writeToURL(fileURL, atomically: true);
var pin:MKAnnotationView = MKAnnotationView();
UIGraphicsBeginImageContextWithOptions(image.size, true, image.scale);
image.drawAtPoint(CGPointMake(0.0, 0.0));
var rect:CGRect = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
for annotation in self.attractionDetailMap.annotations as! [MKAnnotation]{
var point:CGPoint = snapshot.pointForCoordinate(annotation.coordinate);
if(CGRectContainsPoint(rect, point)) …Run Code Online (Sandbox Code Playgroud) mapkit ×10
ios ×6
objective-c ×4
iphone ×2
annotations ×1
cocoa-touch ×1
ios6 ×1
limit ×1
maps ×1
memory ×1
mkannotation ×1
mkmapview ×1
region ×1
swift ×1
uiscrollview ×1
xcode4 ×1