标签: mapkit

iPhone:在MKMapView中检测Tap

如何在实例上检测到单击MKMapView?我是否必须继承MKMapView并重写该touchesEnded方法?

谢谢,

-克里斯

cocoa-touch mapkit mkmapview ios

22
推荐指数
2
解决办法
2万
查看次数

在Swift中动画MapKit注释坐标变化?

在Swift的iOS 8中使用MapKit时,如何设置自定义注释的地图位置变化的动画?我这样说:

UIView.animateWithDuration(0.25) {
    var loc = ann.coordinate
    loc.latitude = loc.latitude + 0.0005
    loc.longitude = loc.longitude + 0.001
    ann.coordinate = loc
}
Run Code Online (Sandbox Code Playgroud)

... ann自定义注释MyAnnotation在哪里.注释是跳跃而不是动画,到新的坐标位置.

令人讨厌的是,如果我在Objective-C中编写MyAnnotation,动画效果很好.但如果我在Swift中编写它,我就不再动画了!

仅供参考,这是我的MyAnnotation的Swift代码:

class MyAnnotation : NSObject, MKAnnotation {
    var coordinate : CLLocationCoordinate2D
    var title: String!
    var subtitle: String!

    init(location coord:CLLocationCoordinate2D) {
        self.coordinate = coord
        super.init()
    }
}
Run Code Online (Sandbox Code Playgroud)

animation mapkit mkannotation ios swift

22
推荐指数
1
解决办法
7099
查看次数

iOS:加载MKMapView并添加注释/叠加层时的通知?

我知道用于在加载地图并添加注释和叠加层时让我知道的委托方法.(mapViewDidFinishLoadingMap: mapView:didAddAnnotationViews: mapView:didAddOverlayViews:)

我想要创建一个UIImage从我的MKMapView东西一切都已加载.目前我正在创建我的UIImage曾经mapView:didAddOverlayViews:被调用,但这并不总是可靠的,因为有时叠加需要更长的时间来添加,有时mapViewDidFinishLoadingMap:被调用不止一次或者需要很长时间才能加载.有时它不会被调用因为缓存了瓷砖.因此,很难确切知道什么时候加载了.我尝试过使用计时器,但这也不能让它变得可靠.

我的问题是,我怎么知道什么时候一切都已完全加载,包括所有地图图块,所有注释和所有叠加?

cocoa-touch objective-c mapkit mkmapview ios

21
推荐指数
2
解决办法
9396
查看次数

使用MapKit ios的渐变折线

我正在尝试使用叠加(MKOverlay)跟踪MKMapView上的路线.但是,根据当前的速度,如果颜色正在变化(例如,如果用户从65mph驱动到30mph),我想要在跟踪路线时使用渐变来执行类似Nike应用程序的操作(例如,从绿色变为橙色).

这是我想要的截图:

渐变叠加图像

因此,每隔20米,我使用以下方法添加从旧坐标到新坐标的叠加:

// Create a c array of points. 
MKMapPoint *pointsArray = malloc(sizeof(CLLocationCoordinate2D) * 2);

// Create 2 points.
MKMapPoint startPoint = MKMapPointForCoordinate(CLLocationCoordinate2DMake(oldLatitude, oldLongitude));
MKMapPoint endPoint = MKMapPointForCoordinate(CLLocationCoordinate2DMake(newLatitude, newLongitude));

// Fill the array.
pointsArray[0] = startPoint;
pointsArray[1] = endPoint;

// Erase polyline and polyline view if not nil.
if (self.routeLine != nil)
    self.routeLine = nil;

if (self.routeLineView != nil)
    self.routeLineView = nil;

// Create the polyline based on the array of points.
self.routeLine = [MKPolyline polylineWithPoints:pointsArray count:2];

// Add …
Run Code Online (Sandbox Code Playgroud)

overlay gradient mapkit mkmapview ios

20
推荐指数
3
解决办法
1万
查看次数

MapKit缩放到用户当前位置

我试图简单地在地图上显示用户的位置,但是我需要在应用程序启动时,地图应该缩放到当前位置,但我不知道为什么地图根本不会缩放,它是这样的:

在此输入图像描述

这是代码:

class MapViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate {

    @IBOutlet weak var mapView: MKMapView!
    var locationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()

        mapView.delegate = self
        mapView.showsUserLocation = true
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.requestWhenInUseAuthorization()
        locationManager.delegate = self
        DispatchQueue.main.async {
            self.locationManager.startUpdatingLocation()
        }
    }

    func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
        let location = locations.last as! CLLocation
        let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
        var region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.1, longitudeDelta: 0.1))
        region.center = mapView.userLocation.coordinate
        mapView.setRegion(region, animated: true)
    }
Run Code Online (Sandbox Code Playgroud)

iphone xcode mapkit ios swift

20
推荐指数
3
解决办法
4万
查看次数

MKMapView setRegion"捕捉"到预定义的缩放级别?

任何人都可以确认setRegion"捕捉"到预定义的缩放级别,以及此行为是否与设计(虽然未记录)或已知错误一样?具体来说,似乎setRegion捕捉到与用户双击地图时使用的缩放级别相对应的相同缩放级别.

我正在尝试恢复以前保存的区域,但如果通过缩放缩放而不是双击缩放设置保存的区域,则此行为无法实现.

如果我在地图的当前区域调用regionThatFits,那么在mapkit方面的事情就会被打破的一个重要线索就是如此.它应该返回相同的区域(因为它显然适合地图的框架),但它返回的区域对应于下一个更高的预定义缩放级别.

setVisibleMapRect的行为类似.

任何进一步的见解或信息将不胜感激.

我找到了这些相关的帖子,但都没有包含解决方案或确切的确认,这实际上是一个mapkit错误:

MKMapView setRegion:奇怪的行为?

MKMapView显示错误保存的区域

编辑:

这是一个演示该问题的示例.所有值对我的地图视图的宽高比都有效:

MKCoordinateRegion initialRegion;
initialRegion.center.latitude = 47.700200f;
initialRegion.center.longitude = -122.367109f;
initialRegion.span.latitudeDelta = 0.065189f;
initialRegion.span.longitudeDelta = 0.067318f;
[map setRegion:initialRegion animated:NO];
NSLog(@"DEBUG initialRegion:  %f  %f  %f  %f", initialRegion.center.latitude, initialRegion.center.longitude, initialRegion.span.latitudeDelta, initialRegion.span.longitudeDelta);
NSLog(@"DEBUG map.region:  %f  %f  %f  %f", map.region.center.latitude, map.region.center.longitude, map.region.span.latitudeDelta, map.region.span.longitudeDelta);
Run Code Online (Sandbox Code Playgroud)

OUTPUT:

DEBUG initialRegion:  47.700199  -122.367111  0.065189  0.067318
DEBUG map.region:  47.700289  -122.367096  0.106287  0.109863
Run Code Online (Sandbox Code Playgroud)

请注意纬度/经度增量值的差异.地图的值几乎是我要求的两倍.较大的值对应于用户双击地图时使用的缩放级别之一.

iphone mapkit mkmapview

19
推荐指数
2
解决办法
7886
查看次数

如何在ios地图中突出显示国家/地区

我正在构建一个应用程序,我必须在世界地图中动态突出显示某些国家/地区. 像这样

在此输入图像描述

总之,我想自定义ios地图的整个视图,如图所示.可以使用MapKit完成,还是有任何其他方法.提前致谢

mapkit mkmapview xcode4.5 ios6.1

19
推荐指数
1
解决办法
5905
查看次数

在iOS8中打破了MapKit Tile Overlay

我有这个代码在我的应用程序中通过默认的Apple 实现OSM :

dispatch_async(dispatch_get_main_queue(), ^{
    NSString *template = @"http://tile.openstreetmap.org/{z}/{x}/{y}.png";
    MKTileOverlay *overlay = [[MKTileOverlay alloc] initWithURLTemplate:template];
    overlay.canReplaceMapContent = YES;
    [self.mapView addOverlay:overlay level:MKOverlayLevelAboveLabels];});
Run Code Online (Sandbox Code Playgroud)

和:

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay {
if ([overlay isKindOfClass:[MKTileOverlay class]]) {
    return [[MKTileOverlayRenderer alloc] initWithTileOverlay:overlay];
}
else return nil;
}
Run Code Online (Sandbox Code Playgroud)

在iOS 7中它很好,但现在它返回多次并且根本没有加载地图:

<Error>: ImageIO: CGImageSourceCreateWithData data parameter is nil
Run Code Online (Sandbox Code Playgroud)

我该如何解决?我试图重构我的代码,所以现在第一块代码:

dispatch_queue_t fetchTiles = dispatch_queue_create("fetcher", NULL);
dispatch_async(fetchTiles, ^{
    NSString *template = @"http://tile.openstreetmap.org/{z}/{x}/{y}.png";
    MKTileOverlay *overlay = [[MKTileOverlay alloc] initWithURLTemplate:template];
    overlay.canReplaceMapContent = YES;
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.mapView addOverlay:overlay level:MKOverlayLevelAboveLabels];});});
Run Code Online (Sandbox Code Playgroud)

但这似乎并没有解决问题.

objective-c openstreetmap mapkit ios ios8

19
推荐指数
1
解决办法
2288
查看次数

使用iphone mapkit获取tapped坐标

我正在使用apple的mapkit框架制作应用程序.我想要做的是从你按的位置获取经度和纬度.我使用以下代码从用户当前位置获取坐标:

- (IBAction)longpressToGetLocation:(id)sender {
    CLLocationCoordinate2D location = [[[self.mapView userLocation] location] coordinate];
    NSLog(@"Location found from Map: %f %f",location.latitude,location.longitude);
}
Run Code Online (Sandbox Code Playgroud)

如何让代码显示按下的位置而不是userlocation?

objective-c mapkit ios

18
推荐指数
2
解决办法
2万
查看次数

把CLLocationCoordinate2D放到Swift的CLLocation中

我有一个我想要调用的方法但是当我回到地图的中心时,它处于CLLocationCoordinate2D类型.

如何将CLLocationCoordinate2D的结果放入CLLocation?

mapkit cllocation ios cllocationcoordinate2d swift

18
推荐指数
1
解决办法
1万
查看次数