我想为用户的位置显示蓝色脉冲点.我这样做:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
//some other stuff here
[self.mapView setShowsUserLocation:YES];
}
Run Code Online (Sandbox Code Playgroud)
但我最终得到了
-[MKUserLocation establishment]: unrecognized selector sent to instance 0x125e90
Run Code Online (Sandbox Code Playgroud)
我应该以其他方式这样做吗?
- 编辑 -
我也这样做,这是我最终获得上述异常的地方:
- (MKAnnotationView *) mapView:(MKMapView *)_mapView viewForAnnotation:(AddressNote *) annotation{
if(annotation.establishment != nil){
//do something}
Run Code Online (Sandbox Code Playgroud)
establishment是我在AddressNote上的一个自定义类.当establishment具有值时,会发生异常.如果我没有设置ShowsUserLocation,一切正常,但当然,我没有看到用户位置.
我的应用程序中有两个视图,一个是一般视图,其中CoreLocation在用户在视图中执行其他操作时计算用户位置.用户在触摸按钮时访问第二个视图,允许他们使用mapview和MapKit更准确地定位自己,我希望此视图中的mapview显示CoreLocation已在第一个视图中识别的位置并继续根据另一个视图中CoreLocation的更新显示此位置.
这是创建封装CoreLocation内容的单例并在视图中使用地图引用或使用通知的最佳方法吗?或者为我的场景使用其他一些更好的练习?
谢谢
我想检测一下注释引脚(的mapkit),以便我可以对该事件执行操作.
现在,如果我触摸注释引脚,则会弹出默认注释标记.我想定制它来触摸引脚时调用我的方法.
我使用自定义图像进行mapkit注释.但是我在使用自定义图像时遇到的主要问题是,当缩小时,注释不在地图上的正确位置,并且只有在我一直向下放大时,它才会显示注释点在正确的位置.似乎当我使用常规引脚MKPinAnnotationView时,它正常工作,因为引脚位于正确的位置放大或缩小,提前感谢任何可以提供帮助的人.
我使用的代码如下:
- (MKAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
NSLog(@"welcome into the map view annotation");
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
MKAnnotationView *pprMapNote = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pprMapNote"];
pprMapNote.image = [UIImage imageNamed:[NSString stringWithFormat:@"GPS_note.png"]];
pprMapNote.canShowCallout = YES;
pprMapNote.centerOffset = CGPointMake(-21,-60);
pprMapNote.calloutOffset = CGPointMake(0, 0);
//[pprMapNote addSubview:pprMapNoteImg];
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self
action:@selector(showDetail)
forControlEvents:UIControlEventTouchUpInside];
pprMapNote.rightCalloutAccessoryView = rightButton;
//remember to write in conditional for the different icons that should be loaded based on location
UIImageView *pprNoteLocIcon = [[UIImageView alloc] …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用来自网址的图片创建自定义MKAnnotationView.
当设备具有视网膜显示时,MKAnnotationView的图像模糊,因为它的分辨率加倍.
如果图像来自应用程序,它将加载@ 2x图像(如果存在),但如果您从这样的网址设置图像,例如:
- (MKAnnotationView *) mapView:(MKMapView *) mapView viewForAnnotation:(id ) annotation
{
MKAnnotationView *customAnnotationView=[[MKAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:nil];
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:@"http://www.interaction-design.org/images/icons/play-button-red-300x300.png"]];
UIImage *img = [UIImage imageWithData:imageData];
[customAnnotationView setImage:img ];
return customAnnotationView;
}
Run Code Online (Sandbox Code Playgroud)
你会看到视网膜显示器上的图像非常像素化.
有什么建议吗?谢谢
cocoa-touch objective-c mapkit mkannotation mkannotationview
我想在iOS默认Map App中的两个位置之间实现get direction功能,我试过这个
Class itemClass = [MKMapItem class];
if (itemClass && [itemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) {
// Use iOS 6 maps
NSString *latString = @"23.0300";
NSString *longString = @"72.5800";
CLLocationCoordinate2D ctrpoint;
ctrpoint.latitude = [latString doubleValue];
ctrpoint.longitude = [longString doubleValue];
MKPlacemark *placemark2 = [[MKPlacemark alloc] initWithCoordinate:ctrpoint addressDictionary:nil];
MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark2];
[mapItem openInMapsWithLaunchOptions:nil];
}
Run Code Online (Sandbox Code Playgroud)
但它显示方向错误如下:
我甚至打开了地图应用程序,找到了我当前的位置,在离我所在位置最近的地图上添加了一个图钉,并且获取方向仍然无效.
此外,"总之,即使在本机应用程序中,Get Direction也无法正常工作"任何人都可以帮助我实现这一目标吗?
这是我绘制第一条线的代码,对于另一条具有另一种颜色的线我该怎么办?
func mapView(mapView : MKMapView! , rendererForOverlay overlay: MKOverlay!) ->MKOverlayRenderer! {
if overlay is MKPolyline {
var polyLineRenderer = MKPolylineRenderer(overlay: overlay)
polyLineRenderer.strokeColor = UIColor.blackColor()
polyLineRenderer.lineWidth = 10
return polyLineRenderer
}
return nil
}
Run Code Online (Sandbox Code Playgroud) 我目前正在使用Swift语言在iOS上开发地图应用程序.我想要一个建议,因为在我绘制地图视图上的所有引脚后
(我使用JSON框架从我的服务器接收数据调用Alamofire)
我想在地图上显示所有注释的副标题以显示与用户当前位置的距离.
现在它可以在地图视图上添加注释,但只能根据从我的服务器接收的信息显示标题和副标题.
谢谢.
我想移动MKMapView指南针.我希望通过以下方式获得它的参考:
let compassView = mapView.subviews.filter {$0 is NSClassFromString("MKCompassView")}
Run Code Online (Sandbox Code Playgroud)
然而,编译器抱怨"使用未声明的类型'NSClassFromString'".我该如何修复此代码?
现在,我的应用程序显示一个customUserAnnotationView,其中包含用户批注的自定义图像(您可以在ViewController.swift中看到它)。我还创建了一个自定义UIView,希望将其用作用户注释上方的注释(其代码和图像位于SpeechBubble.swift下)。
我想结合这两个对象,以便可以显示CustomUserAnnotationView和上面的注释中放置的Custom UIView(SpeechBubble.swift)。
我尝试从 多个 mapbox 教程制作Frankenstein程序的尝试对我来说还没有成功。我只想将我创建的自定义注释类放在图像上方,并可能添加一个小三角形以使其看起来像气泡。
ViewController.swift
import Mapbox
class ViewController: UIViewController, MGLMapViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let mapView = MGLMapView(frame: view.bounds)
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
mapView.delegate = self
// Enable heading tracking mode so that the arrow will appear.
mapView.userTrackingMode = .followWithHeading
// Enable the permanent heading indicator, which will appear when the tracking mode is not `.followWithHeading`.
mapView.showsUserHeadingIndicator = true
view.addSubview(mapView)
let idea = UITextView(frame: CGRect(x: 0, y: 0, width: 100, height: 40)) …Run Code Online (Sandbox Code Playgroud) mapkit ×10
ios ×6
iphone ×4
swift ×4
cocoa-touch ×2
mkmapview ×2
objective-c ×2
alamofire ×1
annotations ×1
google-maps ×1
ios11 ×1
ios4 ×1
mapbox ×1
mkannotation ×1
mkpolyline ×1
polyline ×1
xcode ×1