我想在地图视图中显示Google地图,我想在其中绘制多边形/圆形.
有什么建议?
如果我想在地图上显示用户位置,并在同一时间记录用户的位置,它是一个好主意,添加一个观察者userLocation.location并记录位置,或者我应该仍然使用CLLocationManager用于记录用户位置和使用方法mapView.showUserLocation显示用户的当前位置(蓝色指示灯)?我想显示MapKit API支持的默认蓝色指示器.
另外,这是一个粗略的示例代码:
- (void)viewDidLoad {
...
locationManager = [[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = DISTANCE_FILTER_VALUE;
locationManager.delegate = self;
[locationManager startUpdatingLocation];
myMapView.showUserLocation = YES;
[myMapView addObserver:self forKeyPath:@"userLocation.location" options:0 context:nil];
...
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
// Record the location information
// ...
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
NSLog(@"%s begins.", __FUNCTION__);
// Make sure that the location returned has the desired accuracy
if (newLocation.horizontalAccuracy <= manager.desiredAccuracy)
return;
// Record the …Run Code Online (Sandbox Code Playgroud) 我有一个自定义的MKOverlayView,它绘制了一个简单的线.在drawMapRect:我正在设置CGContextSetLineWidth(context, 30);当完全放大时看起来很好,但是当你缩小时,线条变得越来越薄.MKOverlayView参考说它会自动缩放到地图的缩放级别.无论我的缩放级别如何,我如何强制它绘制相同的宽度?我注意到MKPolylineView(和MKPolygonView)正确执行此操作...无论何时缩放以调整以保持相同的宽度,您都可以看到线条的宽度调整大小.我怎样才能在overlayView中执行此操作?
关于MKMapView的最大缩放的stackoverflow有很多问题和答案,例如:
不幸的是,没有答案实际上对我有用(或者我没有正确实施).我无法模拟原生地图的行为,即限制缩放级别而不"反弹"或重新恢复.
这是我使用的代码:
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
{
if( mapView.region.span.latitudeDelta<0.001 || mapView.region.span.longitudeDelta<0.001){
MKCoordinateRegion region =mapView.region;
region.span = MKCoordinateSpanMake(0.001, 0.001);
mapView.region = region;
[mapView setRegion:mapView.region animated:NO];
}
}
Run Code Online (Sandbox Code Playgroud)
当用户捏合和缩放地图并且地图达到最大缩放(由我设置)时,地图不应放大然后反弹.可能吗?
我正在我的应用程序中实现一个地图功能,我允许用户通过平移来设置他们当前的位置.
这一切的时候,我想有一个MKAnnotation在centerCoordinate.所以我想要做的是跟踪地图的centerCoordinate何时更改并正确更改注释的坐标.这种行为与Uber,Hailo和其他人的行为类似.
我尝试了基于时间的实现,每一个0.00001s的centerCoordinate将进行检查和注释也将被移动.但是如果地图没有轻轻地轻弹,那么注释会从一个地方跳到另一个地方,这不会形成一个好的UI.
我尝试的另一个实现是通过手势识别器和MKMapView(regionDidChange/ regionWillChange)的委托方法.这再次成为一个非常突然的过渡.
任何人都可以告诉我如何更好地做到这一点?
我在该领域有一个应用程序在前台崩溃.我在根视图控制器中有一个MKMapView.此根视图控制器在顶部显示模态视图控制器.当模态视图控制器被解除时,在调用其viewWillAppear方法之后,在根视图控制器中呈现MKMapView时,似乎发生了崩溃.这发生在ios7中.任何人都知道造成这种崩溃的原因是什么?崩溃发生在前台,并且与initWithFrame中偶尔出现的iOS 6 MKMapView崩溃不一样
堆栈跟踪:
Exception Type: SIGSEGV
Exception Codes: SEGV_ACCERR at 0x200000a0
Crashed Thread: 13
0 IMGSGX543GLDriver 0x2efadfd6 sgxBindCurrentTextures + 118
1 IMGSGX543GLDriver 0x2efaf143 sgxBeginRender + 399
2 IMGSGX543GLDriver 0x2efa75c3 glrClearCore + 235
3 IMGSGX543GLDriver 0x2efa73e5 glrClear + 193
4 GLEngine 0x323640c7 glClear_Exec + 395
5 VectorKit 0x37bf1531 -[VKMapModel drawScene:withContext:] + 125
6 VectorKit 0x37bf13f1 -[VKMapModel recursiveDrawScene:withContext:pass:] + 189
7 VectorKit 0x37bf12d5 -[VKModelObject recursiveDrawScene:withContext:pass:] + 237
8 VectorKit 0x37bf11e1 -[VKWorld drawScene:withContext:] + 45
9 VectorKit 0x37bf0a0d -[VKScreenCanvas _renderCore:] …Run Code Online (Sandbox Code Playgroud) 在我的地图应用程序中,我想要显示带有图像的彩色背景圆圈,而不是显示图钉.背景的颜色(下图中的绿色阴影)圆是动态的.它将如下图所示:

我创建了在"drawRect"中绘制颜色的TCircleView.
为了显示类似的注释,我创建了TCircleView和UIImageView的对象并将它们添加到MKAnnotationView对象.它看起来很好,可见如预期.
但它不允许检测点击/触摸以显示呼叫.
我正在使用以下代码:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
if ([annotation isKindOfClass:[MKPointAnnotation class]]) {
return nil;
}
static NSString *annotationIdentifier = @"StickerPin";
MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
if (!annotationView) {
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationIdentifier];
annotationView.canShowCallout = YES;
}
TCircleView* circleView = [[TCircleView alloc] init];
circleView.green = [postObj[@"severity"] floatValue]; //dynamic value coming from server
UIImageView* imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Piano"]];
CGRect r = imgView.frame;
r.size.height = r.size.width = 60;
imgView.frame = r;
circleView.frame = r; …Run Code Online (Sandbox Code Playgroud) 我有一个覆盖在地图上的UIView,我正在两个坐标之间的屏幕空间中绘制一些图形
- (CGPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate toPointToView:(UIView *)view
Run Code Online (Sandbox Code Playgroud)
问题是当地图非常放大和倾斜(类似3D)时,离屏的坐标的像素位置停止一致.有时函数会返回NaN,有时会返回正确的数字,而其他函数会跳转到屏幕的另一侧.
不知道如何更好地解释它.有没有人碰到这个?
我刚刚用GUI创建了CustomCallout.xib.我想将它用作我的注释的自定义标注,但我不知道应该在哪里设置要显示的视图以及如何将值传递给该视图.
我想要显示的标注视图如下所示.
这是我的自定义注释的代码.
class MapPin : MKPointAnnotation {
var name: String
var street: String
var type: String
var postCode: String
init(name: String, street: String, type: String, postCode: String) {
self.name = name
self.street = street
self.type = type
self.postCode = postCode
}}
Run Code Online (Sandbox Code Playgroud)
我的视图控制器:
import UIKit
import MapKit
class ViewController: UIViewController, MKMapViewDelegate {
@IBOutlet var mapView: MKMapView!
let span = MKCoordinateSpanMake(0.05, 0.05)
override func viewDidLoad() {
super.viewDidLoad()
self.mapView.delegate = self
let location = CLLocationCoordinate2D(
latitude: …Run Code Online (Sandbox Code Playgroud) Fabric/Crashlytics正在记录以下崩溃(到目前为止发生了很多崩溃),我无法弄清楚导致它的原因:
Cannot remove an observer<VKMapAnnotationTrackingCameraController 0x155058110> for the key path "heading" from <MKUserLocation 0x153b60790> because it is not registered as an observer.
Run Code Online (Sandbox Code Playgroud)
我假设这是来自MKMapView我允许用户设置地图类型的MKUserTrackingModeFollowWithHeading地方,但我没有添加观察者.
这可能只是一个MapKit错误吗?到目前为止,在过去的30天里发生了32次崩溃,这看起来很多.