gpt4 book ai didi

ios - 快速在 map 上添加 MKTileOverlay

转载 作者:可可西里 更新时间:2023-11-01 02:19:33 26 4
gpt4 key购买 nike

在执行过程中,图像在整个 map 中重复出现。我还可以指定一个 UIImage 来代替 URLTemplate 吗?

我在某个特定位置添加了叠加图像。恰好在当前位置。

谢谢

这是我的代码:

import UIKit
import MapKit


class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {

@IBOutlet weak var mapView: MKMapView!

let locationManager = CLLocationManager()

var latitude: CLLocationDegrees = 0.0
var longitude: CLLocationDegrees = 0.0

var cnt: Int = 0


override func viewDidLoad() {
super.viewDidLoad()

self.mapView.delegate = self

self.mapView.mapType = MKMapType.Satellite

//Map centre
let centre = CLLocationCoordinate2D(latitude: 40.8325769,
longitude: 14.318884400000002)

//Declare span of map
let span = MKCoordinateSpan(latitudeDelta: 0.05,
longitudeDelta: 0.05)

//Set region of the map
let region = MKCoordinateRegion(center: centre, span: span)
self.mapView.setRegion(region, animated: false)
self.mapView.regionThatFits(region)



var template = "http://tile.openstreetmap.org/0/0/0.png"

let carte_indice = MKTileOverlay(URLTemplate:template)


carte_indice.geometryFlipped = true

carte_indice.canReplaceMapContent = false


self.mapView.addOverlay(carte_indice)



}



override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer!
{

if overlay is MKTileOverlay
{
var renderer = MKTileOverlayRenderer(overlay:overlay)

renderer.alpha = 0.8

return renderer
}
return nil
}

}

最佳答案

我认为模板 url 必须是:

var template = "http://tile.openstreetmap.org/{z}/{x}/{y}.png"

问候。

关于ios - 快速在 map 上添加 MKTileOverlay,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31832036/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com