更新#5我想这是赏金时间.即使使用我发布的代码示例,也有100多个视图并且没有人被刺穿.一些声望点怎么样!
更新#4这是一个非常复杂的问题,所以我创建了一个新的基于选项卡的项目,其中包含我的应用程序的部分,我在这里遇到了麻烦.您可以从以下网址下载:http://www.servinitup.net/CustomCalloutAnnotation.zip 随意打开它(需要添加自己的包标识符才能在手机上运行)并玩它,看看你是否可以得到那个darned标注注释随着针移动!
更新#3尝试使setAnnotation成为教程的CalloutMapAnnotationView的公共方法并直接调用它.没有运气.尽管发生了一些奇怪的事情,唯一感动的是标注的小三角形部分.我无法让整个标注移动.
更新#2仍然没有多少运气,但现在一直在寻找以编程方式创建"缩放到缩放"然后立即撤消它的方法,因此用户永远不会看到更改.希望以编程方式执行此操作与手动执行此操作具有相同的效果,并且callout注释将弹回到它的父级.有任何想法吗?
更新#1在这里玩了之后我已经得到了: - 替换self.calloutAnnotation.coordinate = coords;为self.calloutAnnotation.latitude = coords.latitude;self.calloutAnnotation.longitude = coords.longitude;
- 随着更改,如果我稍微捏住地图以在引脚更新后放大或缩小,则标注注释会动画到正确的位置,正好在针.
所以现在我需要弄清楚如何在没有用户实际捏缩放的情况下实现这一点.
原帖
我和其他SO用户一起使用这个非常棒的解决方案来创建自定义标注注释:http: //blog.asolutions.com/2010/09/building-custom-map-annotation-callouts-part-1/
当您使用标准标注(annotationview.canShowCallout = true)并且当位置更新时,引脚在屏幕上移动,标准标注随着引脚一起跟踪,就像它们被锁定在一起一样.
使用上面的自定义标注解决方案时,当我的图钉在位置更新后移动时,标注注释将保留在其原始位置.当然,我想模仿iOS标准,并有自定义标注注释轨道和引脚.
这是我到目前为止的代码,它成功地移动了注释视图,但不是自定义的callout注释视图:
/* core location broadcasts a notification, and my view controller listens to that notification and calls locationManagerDidFindLocation */
- (void)locationManagerDidFindLocation:(NSNotification *)notif {
CLLocation *location = [notif.userInfo objectForKey:@"location"];
CLLocationCoordinate2D coords = [location coordinate];
MKCoordinateSpan span = MKCoordinateSpanMake((5/69), (5/69));
MKCoordinateRegion region = … 我有一个自定义的MKAnnotationView,我在viewForAnnotation中自己设置我的图像.我如何使用MKPinAnnotationView为它设置动画效果?
我的代码是
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString *AnnotationViewID = @"annotationViewID";
MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
if (annotationView == nil)
{
annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
}
annotationView.image = [UIImage imageNamed:@"blah.png"];
annotationView.annotation = annotation;
return annotationView;
}
Run Code Online (Sandbox Code Playgroud) cocoa-touch mapkit mkpinannotationview mkannotationview ios-4.2
对于iOS 6上的中国地图,MapKit似乎根据设备所在的位置选择地图提供者.如果你在中国,它将使用AutoNavi地图,否则它将使用默认的Apple地图.更复杂的是,AutoNavi地图的转换方式与谷歌iOS 5上的地图相同,而默认的Apple地图并未转换.
通过改造我正在谈论中国所有地图都被改造的事实,尽管事实并非如此.相反,中国的一些地图会被改造,而有些地图却没有.
此变换使得难以在地图上正确放置注释,因为地图通常偏移约500米.由于无法反转实际地图的变换,因此解决方案是将相同的偏移应用于注释.
至少对于有限的区域,存在逆转变换的非平凡方式.iOS 6中的问题是知道地图是否被转换为能够适当地补偿注释.在iOS 5上,由于一致地使用了转换后的地图,因此该问题不存在.
下面的上海地图说明了情况(未演示实际的变换偏移).

那么,在运行时是否有任何方法可以了解是否使用了转换或未转换的中国地图?处理这个的其他想法?
编辑:通过中国代理路由网络流量在模拟器中更改地图外观,因此地图提供商的选择必须基于IP.
我正在尝试为CLLocation编写一个类别,以将轴承返回到另一个CLLocation.
我相信我对公式做错了(计算不是我的强项).返回的轴承始终关闭.
我一直在看这个问题并尝试应用被接受为正确答案的更改及其引用的网页:
计算两个CLLocationCoordinate2D之间的方位
http://www.movable-type.co.uk/scripts/latlong.html
谢谢你的任何指示.我已经尝试将其他问题的反馈结合起来,而我仍然没有得到任何东西.
谢谢
这是我的类别 -
----- CLLocation + Bearing.h
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
@interface CLLocation (Bearing)
-(double) bearingToLocation:(CLLocation *) destinationLocation;
-(NSString *) compassOrdinalToLocation:(CLLocation *) nwEndPoint;
@end
Run Code Online (Sandbox Code Playgroud)
--------- CLLocation + Bearing.m
#import "CLLocation+Bearing.h"
double DegreesToRadians(double degrees) {return degrees * M_PI / 180;};
double RadiansToDegrees(double radians) {return radians * 180/M_PI;};
@implementation CLLocation (Bearing)
-(double) bearingToLocation:(CLLocation *) destinationLocation {
double lat1 = DegreesToRadians(self.coordinate.latitude);
double lon1 = DegreesToRadians(self.coordinate.longitude);
double lat2 = DegreesToRadians(destinationLocation.coordinate.latitude);
double lon2 = DegreesToRadians(destinationLocation.coordinate.longitude);
double dLon = lon2 …Run Code Online (Sandbox Code Playgroud) 使用iOS6模拟器运行我的应用程序在调用之前,我在XCode控制台中打印了以下内容viewDidLoad:
在框架中找不到default.styleproto
有没有其他人遇到过这个,如果有的话你找到了原因吗?我的猜测是它与iOS6 Apple Maps有关,但谁知道呢!
编辑
我应该补充一点,我在iOS 5.1模拟器中没有收到此警告.
我有一个扩展NSObject和实现MKOverlay协议的自定义类.因此,我需要实现协议的boundingMapRect属性,这是一个MKMapRect.创造一个MKMapRect我当然可以MKMapRectMake用来做一个.但是,我不知道如何MKMapRect使用我拥有的数据来创建两个点,每个点由纬度和经度指定.MKMapRectMake的文档说:
MKMapRect MKMapRectMake(
double x,
double y,
double width,
double height
);
Parameters
x
The point along the east-west axis of the map projection to use for the origin.
y
The point along the north-south axis of the map projection to use for the origin.
width
The width of the rectangle (measured using map points).
height
The height of the rectangle (measured using map …Run Code Online (Sandbox Code Playgroud) 我有工作代码用一个按钮删除所有地图注释,但在我更新到xcode 7后,我遇到了错误:
类型'MKAnnotation'不符合协议'SequenceType'
if let annotations = (self.mapView.annotations as? MKAnnotation){
for _annotation in annotations {
if let annotation = _annotation as? MKAnnotation {
self.mapView.removeAnnotation(annotation)
}
}
}
Run Code Online (Sandbox Code Playgroud) 我想以MKPinAnnotationView编程方式打开标注.例如,我在地图上放了10个针脚,想要打开离我最近的一个针脚.我该怎么做呢?
Apple已指定'selected'参数MKAnnotationView's,但不鼓励直接设置(这不起作用,尝试过).
其余MKAnnotationView只有一个setHighlighted(同一故事),并且可以ShowCallout方法..
任何提示,如果这是可能的吗?
在iPhone上内置Maps.app上显示方向时,您可以"选择"通过点击它显示的通常3个路线选项之一.我不想复制这个功能并检查一个tap是否在给定的MKPolyline中.
目前我检测到MapView上的点击如下:
// Add Gesture Recognizer to MapView to detect taps
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleMapTap:)];
// we require all gesture recognizer except other single-tap gesture recognizers to fail
for (UIGestureRecognizer *gesture in self.gestureRecognizers) {
if ([gesture isKindOfClass:[UITapGestureRecognizer class]]) {
UITapGestureRecognizer *systemTap = (UITapGestureRecognizer *)gesture;
if (systemTap.numberOfTapsRequired > 1) {
[tap requireGestureRecognizerToFail:systemTap];
}
} else {
[tap requireGestureRecognizerToFail:gesture];
}
}
[self addGestureRecognizer:tap];
Run Code Online (Sandbox Code Playgroud)
我按如下方式处理水龙头:
- (void)handleMapTap:(UITapGestureRecognizer *)tap {
if ((tap.state & UIGestureRecognizerStateRecognized) == UIGestureRecognizerStateRecognized) {
// Check if the …Run Code Online (Sandbox Code Playgroud) 如何在Swift中使用MapKit在用户的当前位置和特定位置之间绘制路径?
我搜索了很多,但没有找到任何有用的Swift特定链接或教程.
mapkit ×10
ios ×6
iphone ×4
ios6 ×2
mkmapview ×2
objective-c ×2
swift ×2
callouts ×1
cllocation ×1
cocoa-touch ×1
haversine ×1
ios-4.2 ×1
ios6-maps ×1
mkannotation ×1
mkoverlay ×1
mkpolyline ×1
swift2 ×1
xcode ×1