在显示PINS的实施类中,我保留了两个变量(标题和子标题),在这个例子中,USA当我点击PIN时只显示单词(标题).
CLLocationCoordinate2D location2D = (CLLocationCoordinate2D){ .latitude = latitudeOfUserLocation, .longitude = longitudeOfUserLocation };
ManageAnnotations *annotation=[[ManageAnnotations alloc]initWithTitle:@"USA" adresseDuTheme:@"Colorado" coordinate:location2D];//only USA is displayed
annotation.pinColor = MKPinAnnotationColorRed; //or red or whatever
[self->mapView addAnnotation:annotation];
MKCoordinateSpan span={.latitudeDelta=1,.longitudeDelta=0.5};
MKCoordinateRegion region={location2D,span};
[mapView setRegion:region];
Run Code Online (Sandbox Code Playgroud)
虽然,在ManageAnnotations类中,我为标题和副标题保留了两个变量.
@interface ManageAnnotations : NSObject<MKAnnotation>{
NSString *_libelle;
NSString *_adresse;
CLLocationCoordinate2D _coordinate;
}
//
@property(nonatomic,assign)MKPinAnnotationColor pinColor;
@property(copy)NSString *libelle;
@property(copy)NSString *adresse;
@property(nonatomic,readonly)CLLocationCoordinate2D coordinate;
-(id)initWithTitle:(NSString*)libelle adresseDuTheme:(NSString*)adresse coordinate:(CLLocationCoordinate2D)coordinate;
@end
#import "ManageAnnotations.h"
@implementation ManageAnnotations
@synthesize pinColor;
@synthesize libelle=_libelle;
@synthesize adresse=_adresse;
@synthesize coordinate=_coordinate;
-(id)initWithTitle:(NSString*)libelle adresseDuTheme:(NSString*)adresse coordinate:(CLLocationCoordinate2D)coordinate{
if((self=[super init])){
_libelle=[libelle …Run Code Online (Sandbox Code Playgroud) 我希望一旦点击"咖啡馆"这样的工具栏按钮,咖啡馆就会显示在可见的地图区域.数据来自Google Places API.一切正常,但单击按钮后不显示引脚.
这里肯定会有延迟.然而,我在后台队列中进行取景并在等待时放置一个旋转轮,并且在取出和解析完成时,旋转轮隐藏.所以我很确定旋转轮消失时的数据就在那里.但是在我滚动地图之前,引脚不会显示出来.
我认为滚动地图只会触发mapView:regionDidChangeAnimated:.但我无法弄清楚它与问题的关系.有人可以帮忙吗?
ViewController.m几乎所有事情发生的源代码.
#import "ViewController.h"
#import "MapPoint.h"
#import "MBProgressHUD.h"
#define kGOOGLE_API_KEY @"AIzaSyCHqbAoY7WCL3l7x188ZM4ciiTixejzQ4Y"
#define kBgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
@interface ViewController () <CLLocationManagerDelegate, MKMapViewDelegate>
@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@property (strong, nonatomic) CLLocationManager *locationManager;
@property int currentDist;
@property CLLocationCoordinate2D currentCentre;
@end
@implementation ViewController
@synthesize mapView = _mapView;
@synthesize locationManager = _locationManager;
@synthesize currentDist = _currentDist;
@synthesize currentCentre = _currentCentre;
- (void)viewDidLoad{
[super viewDidLoad];
}
- (void)viewDidUnload{
[self setMapView:nil];
[super viewDidUnload];
}
// set the map region …Run Code Online (Sandbox Code Playgroud) 我有一组MKPinAnnotationViews可拖动,可以显示标注.当我想通过长按引脚来拖动一个引脚时,它的标注会打开并禁用我的触摸,所以我再次长按以开始拖动.我不想要这种行为,而是喜欢在第一次触摸时拖动引脚.有没有办法控制这种行为?或者有没有办法显示标注Touch Up Inside而不是Touch Down?
我有一张地图,我可以用代码添加pin(注释).我想在运行我的应用程序时,在我的应用程序中添加注释时自动选择此注释,当单击地图而不是注释我的注释取消选择.我可以处理选择并取消选择我的注释,但肯定必须单击注释,直到选择并单击地图(另一个地方而不是注释),直到我的注释取消选择.
我不想要这个.我想在运行我的应用时自动选择我的注释,只需要在地图上点击另一个地方,直到我的注释取消选择.
请指导我.这是我处理select/deselect注释的代码:
static NSString* const ANNOTATION_SELECTED_DESELECTED = @"mapAnnotationSelectedOrDeselected";
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
NSLog(@"2");
NSString *action = (__bridge NSString *)context;
if ([action isEqualToString:ANNOTATION_SELECTED_DESELECTED]) {
BOOL annotationSelected = [[change valueForKey:@"new"] boolValue];
if (annotationSelected) {
NSLog(@"Annotation was selected, do whatever required");
}else {
NSLog(@"Annotation was deselected, do what you must");
}
}
}
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
if ([mapViews.annotations count] > 1) {
for (MKAnnotationView *anAnnotationView in views) {
[anAnnotationView addObserver:self forKeyPath:@"selected" options:NSKeyValueObservingOptionNew context:(__bridge void …Run Code Online (Sandbox Code Playgroud) 我正在使用Daniel提供的自定义MKAnnotationView动画:子类化MKAnnotationView并覆盖setDragState但我遇到了一个问题.
在引脚放置动画之后,当我去移动地图时,mkannotationview会在调用最终引脚放置动画块之前跳回到之前的位置.
在我看来,在动画运行之前调用了dragState = MKAnnotationViewDragStateEnding?如何绕过这个问题并将mkannotationview的最终点设置为动画结束时的点?
#import "MapPin.h"
NSString *const DPAnnotationViewDidFinishDrag = @"DPAnnotationViewDidFinishDrag";
NSString *const DPAnnotationViewKey = @"DPAnnotationView";
// Estimate a finger size
// This is the amount of pixels I consider
// that the finger will block when the user
// is dragging the pin.
// We will use this to lift the pin even higher during dragging
#define kFingerSize 20.0
@interface MapPin()
@property (nonatomic) CGPoint fingerPoint;
@end
@implementation MapPin
@synthesize dragState, fingerPoint, mapView;
- (void)setDragState:(MKAnnotationViewDragState)newDragState animated:(BOOL)animated
{ …Run Code Online (Sandbox Code Playgroud) 这是我的第一个程序。而且,我正在实现MapKit。以下是代码:
import UIKit
import MapKit
class ViewController: UIViewController {
@IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}}
Run Code Online (Sandbox Code Playgroud)
如果我不导入MapKit,则会收到错误消息,因为“弱可能仅适用于类和类绑定的协议类型”。如果这样做,我会得到标题中提到的错误。
我不明白我要去哪里错了。
我正在使用Firebase将注释添加到mapView。这可以通过以下步骤完成:
func getMarkers() {
dbRef.observe(.value, with: { (snapshot) in
for buildings in snapshot.children {
let buildingsObject = Buildings (snapshot: buildings as! FIRDataSnapshot)
let latDouble = Double(buildingsObject.latitude!)
let lonDouble = Double(buildingsObject.longitude!)
self.telephoneNumber = buildingsObject.number
let annotation = myAnnotationView.init(title: buildingsObject.content!, coordinate: CLLocationCoordinate2D.init(latitude: latDouble!, longitude: lonDouble!), duration: buildingsObject.duration!, cost: buildingsObject.cost!, info: "", timestamp: buildingsObject.timestamp, contactNumber: buildingsObject.number!, addedBy: buildingsObject.addedByUser!)
self.mapView.addAnnotation(annotation)
print (snapshot)
}})}
Run Code Online (Sandbox Code Playgroud)
myAnnotationView是AnnotationView的自定义类。
向地图添加注释没有问题。问题在于,如果用户需要删除其注释,则需要将其从mapView中删除。我有一张桌子,上面有所有用户注释,如果他们愿意,他可以在其中删除。这将更新为Firebase控制台,并删除数据。但是,注释仍在地图上,仅当您重置应用程序时,注释才会更新。
我有一种方法来观察deleteChilds,它获得了正确的快照,但我似乎无法引用需要删除的注释。
func removeMarkers() {
dbRef.observe(.childRemoved, with: { (snapshot) in
print (snapshot)
})}
Run Code Online (Sandbox Code Playgroud)
被吐出来的快照在这里:
Snap (-KTo3kdGGA_-rfUhHVnK) { //childByAutoID
addedByUser = …Run Code Online (Sandbox Code Playgroud) 我在自己的mapkit项目中使用了自定义注释(快速3),以在地图上显示多个注释。它正在显示,我只能在第一次单击annotationn。要再次打开注释,我需要在地图上的任意位置单击,然后再次单击注释。有人可以帮助我吗?先感谢您。
这是我正在使用的功能:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation
{
return nil
}
var annotationView = self.map.dequeueReusableAnnotationView(withIdentifier: "Pin")
if annotationView == nil{
annotationView = AnnotationView(annotation: annotation, reuseIdentifier: "Pin")
annotationView?.canShowCallout = false
}else{
annotationView?.annotation = annotation
}
if (indexPin > 0) {
indexPin = indexPin - 1
let pin : PinAnnotation = pinAnotationList[indexPin]
annotationView?.image = UIImage(named: pin.imageName)
}
return annotationView
}
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView)
{
if view.annotation is MKUserLocation
{ …Run Code Online (Sandbox Code Playgroud) 我有麻烦在MapView上选择自定义注释.我尝试了几种方法,没有成功:
您可以在下面的代码中找到所有这些方法:
override func viewDidLoad() {
super.viewDidLoad()
// some more initialization code
for item in items {
let annotation = IdentifiedMKPointAnnotation() // has only one additional property named "id"
annotation.coordinate = CLLocationCoordinate2D(latitude: item.spots[0].latitude!, longitude: item.spots[0].longitude!)
annotation.id = i
self.mapView.addAnnotation(annotation)
i += 1
}
}
// MARK: - MapViewDelegate
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let item = self.items[(annotation as! IdentifiedMKPointAnnotation).id!]
let annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "")
//annotationView.canShowCallout = false
//annotationView.isEnabled = false …Run Code Online (Sandbox Code Playgroud) mapkit ×10
ios ×9
swift ×4
iphone ×3
mkannotation ×3
objective-c ×3
mkmapview ×2
annotations ×1
firebase ×1