标签: mapkit

CLLocationCooperative2D 放入一个数组

我在地图套件上绘制了动态数量的位置。我很好奇如何将当前的纬度和经度放入单个数组中,因为它们当前被打印为单独的对象,而没有像应有的那样绘制地图。我知道问题所在,但不知道如何解决。这是我当前生成坐标的代码 -

  do {
        let place = try myContext.executeFetchRequest(fetchRequest) as! [Places]

        for coords in place{
            let latarray = Double(coords.latitude!)
            let lonarray = Double(coords.longitude!)
            let arraytitles = coords.title!

            let destination:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latarray, lonarray)

        print(destination)

    } catch let error as NSError {
        // failure
        print("Fetch failed: \(error.localizedDescription)")
    }
Run Code Online (Sandbox Code Playgroud)

这是控制台中的打印 - 输出

我需要什么才能使打印看起来正常工作 -所需的输出

我希望你明白我的意思。我非常感谢任何帮助!感谢您的阅读。

dictionary coordinates mapkit cllocationcoordinate2d swift

4
推荐指数
1
解决办法
3622
查看次数

在 MapKit 中的多边形中心添加标签

还有类似名称的问题,例如this,但这不是我要寻找的问题。

基本上我在标准地图上画了一堆MKPolygons,给它们一个笔划,一个随机颜色等。我希望能够“命名”它们,添加一个标签或者可能是一个带有标签的 UIView,这样它看起来就可以了好的。这可能吗?

这是我的地图的样子

在此输入图像描述

这是实现

func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {

    if overlay is MacaronMKPolygon {

        let macaronOverlay = overlay as! MacaronMKPolygon

        let polygonView = MKPolygonRenderer(overlay: macaronOverlay)
        polygonView.strokeColor = UIColor.gray
        polygonView.lineWidth = 1
        polygonView.alpha = shouldShowMacaron ? 1.0 : 0.0
        polygonView.fillColor = macaronOverlay.color
        return polygonView

    }

    return MKOverlayRenderer()
}
Run Code Online (Sandbox Code Playgroud)

mapkit ios mkpolygon swift

4
推荐指数
1
解决办法
3351
查看次数

iOS Mapkit 注释无法拖动

我是 iOS 开发新手,需要在 iOS 地图中实现可拖动注释。我的代码如下。无论我做什么,我都无法获得可拖动的注释,之后我需要获取引脚指向的位置的地址,任何人都可以帮助注释

RegistrationViewController.swift

class RegistrationViewController: UIViewController,UIPickerViewDelegate,UIPickerViewDataSource,MKMapViewDelegate{
    @IBOutlet weak var mapView: MKMapView!

    override func viewDidLoad() {
        super.viewDidLoad()
        var centerLocation = CLLocationCoordinate2DMake(12.964370125970357, 77.59643554937497)
        var mapspan = MKCoordinateSpanMake(0.01, 0.01)
        var mapregion = MKCoordinateRegionMake(centerLocation, mapspan)
        self.mapView.setRegion(mapregion, animated: true)

        let pin = pinAnnotation(title:"hello",subtitle:"how are you",coordinate:centerLocation)
        mapView.addAnnotation(pin)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
        if annotation is MKPointAnnotation {
            let pinAnnotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "myPin")
            pinAnnotationView.pinColor = .purple
            pinAnnotationView.isDraggable = true
            pinAnnotationView.canShowCallout = …
Run Code Online (Sandbox Code Playgroud)

mapkit mkannotation ios swift

4
推荐指数
1
解决办法
1904
查看次数

MapKit 中 MKMarkerAnnotationView 的彩色图像

我正在为 iOS 构建一个应用程序,它允许用户基于位置存储图像。现在我想使用 iOS 中最新的AnnotationView( MKMarkerAnnotationView) 来实现此目的,因为它提供了自动集群。

我的问题是,这个类需要 aglyphTintColor如果没有提供它设置为UIColor().red. iOS 使用这种颜色来为整个图像着色。之后图像就只有这种颜色。我尝试将其设置glyphTintColor为,nil但这会导致图像变红。我也尝试将其设置为,UIColor(red:1.00, green:1.00, blue:1.00, alpha:0.0)但之后图像消失了,您只能看到标记本身。

我希望标记以原始颜色而不是单色显示图像。

谁能帮我解决这个问题吗?

这是我的完整代码:

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    if annotation is MKUserLocation {
        return nil
    }

    let identifier = "PinAnnotationIdentifier"

    var pinView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: identifier)

    pinView?.annotation = annotation
    pinView?.clusteringIdentifier = "clusterId"
    pinView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)


    pinView?.canShowCallout = false
    pinView?.glyphImage = UIImage(named: "image")


    return pinView
}
Run Code Online (Sandbox Code Playgroud)

mapkit mkmapview ios mapkitannotation

4
推荐指数
1
解决办法
3801
查看次数

iOS 中的地理围栏限制

我对 iOS 中的地理围栏限制有疑问。

\n\n

我正在为烟店构建一个应用程序。地点加起来大约有200个。

\n\n

我想让用户在距离商店几英尺远时“自动”签到。

\n\n

Apple 施加的限制是 20。

\n\n

苹果文档

\n\n
\n

区域是依赖于特定硬件功能的共享资源。为了确保所有应用程序都能参与区域监控,Core Location 会阻止任何单个应用程序同时监控超过 20 个区域。要解决此限制,请仅监视靠近用户\xe2\x80\x99s 当前位置的区域。当用户移动时,根据用户\xe2\x80\x99 的新位置更新列表。

\n
\n\n

正如文档中所示,Apple 建议开发人员在用户更新其位置时更新 20 个区域的列表。

\n\n

在此输入图像描述

\n\n

我想到三个问题。

\n\n
    \n
  1. 文档称“Core Location 可防止任何单个应用程序同时监控 20 多个区域”。这是否意味着,作为开发人员,我可以在应用程序中设置区域的位置仅限于 20 个?因为我有 200 个地点(200 个客户希望在他们的商店周围拥有此功能)。

  2. \n
  3. Apple 提供了解决该限制的方法。这是否意味着 20 个区域限制仅适用于应用程序用户?这是否意味着我可以设置 200 个位置,但用户只能看到距离他们最近的 20 个可以签入的位置?

  4. \n
  5. 如果我有 10 个用户使用我的应用程序,并且他们的区域总数超过 20 个位置,会发生什么情况?

  6. \n
\n

core-location mapkit ios clcircularregion

4
推荐指数
1
解决办法
4974
查看次数

如何在 MapKit JS 中创建类似于 Google 的地点自动完成的自动完成查找

我已经成功地使用 Apple 的 MapKit JS 在网页上显示地图和路线,但由于缺乏示例代码,我无法从文档中了解搜索和自动完成是如何工作的。我已经尝试了所有可以使用的搜索词,但似乎无法在任何地方找到任何示例。如果有人可以向我展示 MapKit JS 搜索/自动完成代码的示例,我可能可以找出其余部分来连接类似于 Google 的 Places Autocomplete 的东西。

提前致谢。

javascript autocomplete mapkit

4
推荐指数
1
解决办法
1650
查看次数

没有 UIViewRepresentable 的 SwiftUI 地图叠加

我尝试仅使用 iOS 14 SwiftUI 地图创建带有注释和叠加层的地图视图。我设法创建注释,但由于 MKMapView 委托缺少 MKOverlayRenderer,因此无法创建可见的叠加层。如何附加到地图视图委托以便​​它可以运行其方法

    Map(coordinateRegion: $region, showsUserLocation: true, userTrackingMode: $userTrackingMode, annotationItems: annotations)) { annotation in
        MapAnnotation(coordinate: CLLocationCoordinate2DMake(annotation.latitude, annotation.longitude),
                      anchorPoint: CGPoint(x: 0.5, y: 0.7)) {
            NavigationLink(destination: DetailsView()) {
                VStack {
                    Image(systemName: "mappin")
                        .font(.title)
                        .foregroundColor(.red)
                    Text(annotation.name.split(separator: " ").joined(separator: "\n"))
                        .font(.caption)
                        .bold()
                        .multilineTextAlignment(.center)
                        .foregroundColor(.black)
                        .padding(2)
                        .background(RoundedRectangle(cornerRadius: 4).fill(Color.white.opacity(0.8)))
                        .layoutPriority(1)
                }
            }
        }
    }
    .addOverlays(mapOverlays, delegate: mapDelegate)
Run Code Online (Sandbox Code Playgroud)

和地图扩展方法:

extension Map {
    func addOverlays(_ overlays: [MKOverlay], delegate: MKMapViewDelegate) -> some View {
        // MKMapView.appearance().delegate = delegate // THIS DOES NOT WORK AT …
Run Code Online (Sandbox Code Playgroud)

delegates uikit mapkit swift swiftui

4
推荐指数
1
解决办法
4279
查看次数

MKAnnotation和MKAnnotationView代表什么?

MKAnnotation代表什么?它是否像地图上的笔记 - 就像你打开谷歌地图并点击小图标一样?

objective-c mapkit ipad

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

如何在iPhone中从地址中找到纬度和经度

我正在制作一个我正在获取地址的应用程序,我需要从该地址中找到纬度和经度并在地图中显示该位置

- (void)viewDidLoad 
{
    [super viewDidLoad];

    [mapView setMapType:MKMapTypeStandard];
    [mapView setZoomEnabled:YES];
    [mapView setScrollEnabled:YES];
    mapView.showsUserLocation = YES;
    MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } }; 

    geoCoder.delegate = self;
    [geoCoder start];

    double latitude = 0, longitude = 0;

    region.center.latitude = latitude;   
    region.center.longitude = longitude;  
    region.span.longitudeDelta = 0.01f;
    region.span.latitudeDelta = 0.01f;
    [mapView setRegion:region animated:YES]; 

    [mapView setDelegate:self];

    DisplayMap *ann = [[DisplayMap alloc] init]; 
    ann.title = @"BarRestaurant";
    ann.subtitle = @"..."; 
    ann.coordinate = region.center; 
    [mapView addAnnotation:ann];
}

-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id <MKAnnotation>)annotation …
Run Code Online (Sandbox Code Playgroud)

iphone mapkit

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

将MKMapView点移动到像素坐标

我有一个快速的问题.我使用自定义视图作为我的地图视图的标注附件.我有一些问题,让注释移动到所述视图的右下角.我目前正在尝试获得所选注释的CGPoint坐标,但除此之外,我已经画了一个空白任何帮助将不胜感激.

我正在使用的当前代码(我知道它是不正确的:)

   CGPoint bottomLeftPoint = CGPointMake(xOffset,[self.internalAnnotationCallout view].frame.size.height);
CLLocationCoordinate2D bottomLeftCoord = [self.branchLocation convertPoint:bottomLeftPoint toCoordinateFromView:self.branchLocation];
MKCoordinateSpan span = {latitudeDelta: kMapMultiLatDelta, longitudeDelta: kMapMultiLatDelta};
  MKCoordinateRegion region = {bottomLeftCoord, span};
 [self.branchLocation setRegion:region animated:YES];
//[self.branchLocation setCenterCoordinate:newCenterCoordinate animated:YES];
Run Code Online (Sandbox Code Playgroud)

iphone map mapkit mkmapview ios

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