所以我在地图上散布了一堆注释......一切都只是花花公子.现在我需要能够设置地图的位置和缩放,以便它们完全适合.我怎样才能做到这一点?
我在找到MKAnnotationView异步请求完成后更新自定义映像的方法时遇到问题,并提供有关注释状态的信息.到目前为止,我有这个:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
static NSString *identifier = @"EstacionEB";
if ([annotation isKindOfClass:[EstacionEB class]]) {
EstacionEB *location = (EstacionEB *) annotation;
CustomPin *annotationView = (CustomPin *) [_mapita dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil) {
annotationView = [[CustomPin alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
} else {
annotationView.annotation = annotation;
}
UIImage * image = [UIImage imageNamed:[NSString stringWithFormat:@"%@.png", [location elStatus]]];
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
annotationView.image = image;
NSDictionary *temp = [[NSDictionary alloc]
initWithObjects:[NSArray arrayWithObjects:annotationView, location, nil]
forKeys:[NSArray arrayWithObjects:@"view", …Run Code Online (Sandbox Code Playgroud) 在用户点击引脚,查看标注并点击显示详细视图控制器的显示按钮后,如何保持与MKAnnotation对象关联的数据?我想在详细视图控制器中显示与引脚相关的所有数据.
我有一个简单的MKAnnotation类,看起来像:
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface VoiceMemoryAnnotation : NSObject <MKAnnotation> {
NSString * blobkey;
}
@property (nonatomic, retain) NSString * blobkey;
-(id)initWithBlobkey:(NSString *) key andCoordinate:(CLLocationCoordinate2D) c;
@end
Run Code Online (Sandbox Code Playgroud)
我实现了回调"viewForAnnotation"
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView*singleAnnotationView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:nil];
// PM: this pin will have a callout (i.e. dont' forget to override title function! Else exception thrown)
singleAnnotationView.canShowCallout = YES;
// PM: add disclosure button
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
// PM: when user taps disclosure button, bring …Run Code Online (Sandbox Code Playgroud) 我现在使用Map Kit和Core Location,需要从邮政编码或城市/州获取位置信息.有什么办法吗?
我有以下文件:
annotation.h:
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface annotation : NSObject <MKAnnotation>
@property(nonatomic, assign) CLLocationCoordinate2D coordinate;
@property(nonatomic, copy) NSString *title;
@property(nonatomic, copy) NSString *subtitle;
@end
Run Code Online (Sandbox Code Playgroud)
annotation.m:
#import "annotation.h"
@implementation annotation
@synthesize coordinate, title, subtitle;
@end
Run Code Online (Sandbox Code Playgroud)
在主代码中,它在NSURL其他地方找到了:
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[spinner stopAnimating];
// json parsing
results = [NSJSONSerialization JSONObjectWithData:data options:nil error:nil];
NSMutableArray * locations = [[NSMutableArray alloc] init];
CLLocationCoordinate2D location;
annotation * myAnn;
NSArray *pins = mapView.annotations;
if ([pins count])
{
[mapView removeAnnotations:pins];
}
/* loop through the array, …Run Code Online (Sandbox Code Playgroud) 如何将mapView集中在MKAnnotationView的calloutAccessory上?我知道如何将地图置于实际的annotationView中心,但我不知道如何将地图置于annotationView的calloutAccessory中心.有任何想法吗?
// This centers the map on the MKAnnotationView. However, I need to be able to
// center the map on the MKAnnotationView's calloutAccessory.
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
id<MKAnnotation> annotation = view.annotation;
[self.mapView setCenterCoordinate:[annotation coordinate] animated:YES];
}
Run Code Online (Sandbox Code Playgroud) 所以我正在开发一个项目,其中包括在地图周围放置注释的许多用途.屏幕上会出现注释(这是一个具有更大圆形范围的自定义图像),理想情况下,我希望用户为:
我认为这是一个非常独特的问题,对于有人帮忙应该很有趣,所以玩得开心!谢谢大家!
我regionDidChangeAnimated用于我的mapView.我想检测用户缩放或拖动地图的时间.正在检测拖动,但我似乎无法检测用户缩放地图的时间.我试着用:
func mapView(mapView: MKMapView, regionWillChangeAnimated animated: Bool) {
print("region will change")
}
Run Code Online (Sandbox Code Playgroud)
但是当我缩放我的地图时,它不起作用.
完整代码:
var locationManager: CLLocationManager = CLLocationManager()
var startLocation: CLLocation!
@IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
//get current location
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
self.mapView.showsUserLocation = true
startLocation = nil
let mapDragRecognizer = UIPanGestureRecognizer(target: self, action: "didDragMap:")
mapDragRecognizer.delegate = self
self.mapView.addGestureRecognizer(mapDragRecognizer)
self.mapView.pitchEnabled = true
self.mapView.showsBuildings = true
}
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [CLLocation]) {
let location = locations.last …Run Code Online (Sandbox Code Playgroud) 我有一张地图,在这张地图上我有自定义注释引脚.所有引脚都有相同的自定义图像 当我点击一个图钉时,我需要更改这个注释的图像.我之前使用的是谷歌地图:
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
if marker.userData as? Int != nil {
let marker_tag = marker.userData as! Int
Datas.selectedMarkerIndex = marker_tag
if let selectedMarker = mapView.selectedMarker {
selectedMarker.icon = UIImage(named: "marker_gray")
}
mapView.selectedMarker = marker
marker.icon = UIImage(named: "marker_red")
}
return true
}
Run Code Online (Sandbox Code Playgroud)
这工作正常.但我不知道如何使用MapKit.我想改变选择的标记(图钉)图像.我怎样才能做到这一点?
我也尝试了这个,但没有工作 如何使用Swift在mapkit上更改非选定的注释图像
这是我的代码:
class CustomPointAnnotation: MKPointAnnotation {
var pinImageName:String!
var userData:Int!
}
extension MyView: MKMapViewDelegate {
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let …Run Code Online (Sandbox Code Playgroud) 我的项目是带有很多注释点的地图,由于有pickerView,用户可以查找特定的注释。一切正常,只是所有注释点的列表似乎随机显示。我想按字母顺序对注释进行排序。
这是我当前的工作代码:
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return self.mapView.annotations[row].title ?? "No title"
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
self.mapView.selectAnnotation(self.mapView.annotations[row], animated: true)
}
Run Code Online (Sandbox Code Playgroud)
我曾尝试实现这一点,但没有成功...
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
let sortedNames = self.mapView.annotations.sorted(by: {$0.title < $1.title})
return sortedNames[row].title ?? "No title"
}
Run Code Online (Sandbox Code Playgroud)
我有这个错误:
无法转换类型为'String ??'的值 到预期的参数类型'UIContentSizeCategory'
任何提示将不胜感激。
mapkit ×10
ios ×5
swift ×4
iphone ×3
mkannotation ×3
annotations ×2
ios4 ×2
mkmapview ×2
objective-c ×2
apple-maps ×1
cocoa-touch ×1
google-maps ×1
ios5 ×1