我正在注释我的地图并设置好图像,但是当我点击MapView上的注释时,图像会从我的自定义图像返回到红色图钉.为什么是这样?
- (MKAnnotationView *)mapView:(MKMapView *)newMapView viewForAnnotation:(id )newAnnotation {
MKPinAnnotationView *annotation = [[MKPinAnnotationView alloc] initWithAnnotation:newAnnotation reuseIdentifier:@"currentloc"];
if (annotation == nil) {
annotation = [[MKAnnotationView alloc] initWithAnnotation:newAnnotation reuseIdentifier:@"currentloc"];
}
annotation.image = [UIImage imageNamed:@"anno.png"];
annotation.canShowCallout = YES;
annotation.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bus_stop_30x30.png"]];
annotation.leftCalloutAccessoryView = imgView;
return annotation;
}Run Code Online (Sandbox Code Playgroud)
我的代码看起来与一些不会产生此问题的示例代码相同.
我正在开发一款iPhone应用程序,可以显示某些位置上有多个圆形叠加层的地图.当我添加超过6个圆圈时,我遇到严重的内存问题和崩溃,并且我缩小到足以让它们全部可见.当我放大以便只能看到2个圆圈时,一切都很好.当我删除MKOverlays时,一切正常.
谁认识到这种行为?
用于创建叠加层的代码.我将叠加层存储在NSMutableDictionary中以供将来参考(能够从地图中删除它们并防止双重叠加)
- (void)updateMarkersForZones:(NSArray *)zones {
NSLog(@"MapViewController: Update Markers");
// For each zone, show a marker
for (Zone* zone in zones) {
NSString *keyMarker = [NSString stringWithFormat:@"%d-marker", zone.id];
MKCircle *circle = [overlayCache objectForKey:keyMarker];
if (circle == nil) {
// draw the radius circle for the marker
double radius = MAX(zone.markerRadius * 1.0, 1.0);
circle = [MKCircle circleWithCenterCoordinate:zone.location radius:radius];
[mapView addOverlay:circle];
// store the circle in a cache for future reference
[overlayCache setObject:circle forKey:keyMarker];
}
}
}
Run Code Online (Sandbox Code Playgroud)
用于生成叠加视图的代码
#pragma mark …Run Code Online (Sandbox Code Playgroud) 我正计划在iPhone上徒步旅行的地图项目.
由于移动网络可能无法覆盖徒步旅行区域.因此,有必要预先缓存该区域的地图(Google).
1)MapKit Framework是否支持在本地缓存iPhone上的Google Map?2)MapKit Framework可以支持在GPS期间使用离线地图吗?
谢谢.
我想确定用户是否滚动了超过地图的某个百分比,然后禁用地图从用户位置居中(类似于地图应用的工作方式).
我不确定使用哪种方法.
我认为创建一个矩形并查看矩形是否包含当前中心点是很简单的,但是我必须以IOS 3为目标,因此我无法使用许多较新的Mapkit apis.
我已尝试使用CLLocation,并在当前mapcenter和用户位置之间使用distanceFrom,但我试图弄清楚该距离是否为某个百分比.
是否可以将CLLocation对象用作字典中的键?当我尝试这个时,[dictionary objectForKey:clLocationObj]总是返回nil,即使已经插入了具有完全相同纬度和经度的CLLocation键.我能做错什么?
for (Location *location in someArray) {
CLLocation *locationKey = [[CLLocation alloc] initWithLatitude:[location.latitude doubleValue] longitude:[location.longtitude doubleValue]];
LocationAnnotation *annotationAtLocation = [self.uniqueLocations objectForKey:locationKey];
if (annotationAtLocation == nil)
NSLog(@"this is always nil");
}
Run Code Online (Sandbox Code Playgroud)
我从调试中知道,在someArray中有多个Location位置具有相同的纬度和经度.
当然我用谷歌搜索并在stackoverflow中使用搜索.我发现了一些类似的讨论:
http://forums.bignerdranch.com/viewtopic.php?f=49&t=490
NSInvalidUnarchiveOperationException:无法解码类的对象(UITableViewCellContentView)
......还有那么多的副本:)
但是,我没有使用SDK 3.2但5.0(其中一个链接的讨论表明它在SDK 3.2的某些测试版中是错误的).
其他讨论和答案表明框架MapKit未正确包含在内.我按照这些说明尝试了几种方法.
我仍然收到此错误.它被打破了
[super loadView];
Run Code Online (Sandbox Code Playgroud)
在我自己的视图控制器中
- (void)loadView {
Run Code Online (Sandbox Code Playgroud)
方法.视图本身是在IB中构建的.除了其他项目之外还有一个MKMapView.
我在两个xcode项目中使用MKMapView.两者都是在xcode 3.2中启动的,现在已迁移到xcode 4.在其中一个项目中,代码工作正常,在另一个项目中,我得到了这个运行时错误.我没有发现这些项目的设置之间有任何重大差异可以解释这种不同的行为.
当前的解决方法是删除任何与Map View相关的代码(和IB项).但最后我宁愿包含那个地图视图,因为它确实有用:)
任何建议表示赞赏.
赫尔曼
我一直在测试CoreLocation各个方面的准确性,并惊讶地发现传递给CLLocationMangerDelegate方法的新旧位置提供的准确性值:( void)locationManager:didUpdateToLocation:fromLocation本身非常不准确.
走一段路面(沿着一段道路,沿着建筑物的一侧)我发现,虽然CLLocationManager声称它提供的CLLocations具有5米的水平精度,实际上MKUserAnnotation显示的位置是任何高达距离我所知道的位置30米(通常显示为一排建筑物的对面).这表明精确度读数本身并不准确.CLLocationManager告诉我它的坐标精确到5米以内但实际上多达30米.
为了澄清,这不是缓存/时间戳问题它在某些领域是可重复的,而不是随着时间的推移而改进的东西.
还有其他人遇到过这个问题吗?
我需要在地图上显示MKOverlay,但无法让它实际显示.
我正在关注Apple的位置感知编程指南中的示例,并且不会显示叠加层.任何帮助将不胜感激,这是我制作的第一个iPhone应用程序,所以我可能会遗漏一些简单的东西.
NavViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface NavViewController : UIViewController <MKMapViewDelegate> {
}
@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@end
Run Code Online (Sandbox Code Playgroud)
NavViewController.m
#import "MSUNavViewController.h"
#import <CoreLocation/CoreLocation.h>
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
if ([overlay isKindOfClass:[MKPolygon class]])
{
MKPolygonView* aView = [[MKPolygonView alloc] initWithPolygon:(MKPolygon*)overlay];
aView.fillColor = [[UIColor cyanColor] colorWithAlphaComponent:0.2];
aView.strokeColor = [[UIColor blueColor] colorWithAlphaComponent:0.7];
aView.lineWidth = 3;
return aView;
}
return nil;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Define an overlay that covers Colorado.
CLLocationCoordinate2D …Run Code Online (Sandbox Code Playgroud) 谷歌地图现在可以在Appstore for IOS 6中使用.我有一个应用程序利用MAPKIT和WebView显示使用谷歌网络服务的驾驶方向.为了在Native Apple MAP应用程序中显示Route,我使用类似于此的代码.
MKMapItem *mapItem = [[MKMapItem alloc]initWithPlacemark:place];
NSDictionary *options = @{
MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving
};
[mapItem openInMapsWithLaunchOptions:options];
Run Code Online (Sandbox Code Playgroud)
我想在用户设备上安装的New Google MaP App中向用户显示Route,将其UI嵌入我应用中的View中.
请指导我.
我了解了当前的NSXMLParser.我阅读了很多教程,但没有人能告诉我它是如何工作的.StackOverflow上有一个教程?我的问题是我的应用程序中的KML读取结构,并使用MKMapView进行显示
我的Parser类看起来像:
#import <Foundation/Foundation.h>
@interface Parser : NSXMLParser
@property (nonatomic, strong) NSString *rowElementName; // this is the element name that identifies a new row of data in the XML
@property (nonatomic, strong) NSArray *attributeNames; // this is the array of attributes we might want to retrieve for that element name
@property (nonatomic, strong) NSArray *elementNames; // this is the list of sub element names for which we're retrieving values
@property (nonatomic, strong) NSMutableArray *items; // after parsing, this is the …Run Code Online (Sandbox Code Playgroud) mapkit ×10
iphone ×6
ios ×5
ios4 ×2
objective-c ×2
annotations ×1
google-maps ×1
gps ×1
ios5 ×1
ios6 ×1
mkmapview ×1
mkoverlay ×1
nsxmlparser ×1