点击表示userLocation的脉动蓝色圆圈会显示"当前位置"标注.有没有办法压制那个?
我一直试图在mapview上放置一个可拖动的注释多年.(我正在使用默认的引脚,而不是我自己的引脚)到目前为止,我只能在设定的坐标处显示它(实际上并不是很大的成就),我需要首先获得注释以对选择作出反应,它不会永远不会被这个didChangeDragState功能所接受.然后我需要能够拖动它,将它放在一个新的位置并获得新位置的坐标.
我对Swift来说是个新手,但我已经开始了一个相当困难的项目.我看了几乎所有我在google上寻找" MKAnnotationSwift中的可拖动mapkit"和类似变体的东西.(编辑:我没有找到任何解释我的问题的答案,所有其他答案都提供了如何上传个性化的答案MKAnnotation.他们都有标题字段,但没有一个答案提到标题字段是必要的,结果证明是主要的问题.他们只提到我应该设置dragState来控制引脚的移动,但在我的情况下,这看起来是不正确的,如下所示)无论如何 !下面是我的代码,我尝试实现mapView并添加注释.
var currentLat:CLLocationDegrees!
var currentLong:CLLocationDegrees!
var currentCoordinate:CLLocationCoordinate2D!
....
override func viewDidAppear(animated: Bool) {
let annotation = PinAnnotationClass()
annotation.setCoordinate(currentCoordinate)
//annotation.setCoordinate(currentCoordinate)
//AnnotationView()
self.mapView.addAnnotation(annotation)
}
override func viewDidLoad() {
super.viewDidLoad()
println("hello!")
self.mapView.delegate = self
loadMap()
findPath()
}
func loadMap()
{
currentCoordinate = CLLocationCoordinate2DMake(currentLat, currentLong)
var mapSpan = MKCoordinateSpanMake(0.01, 0.01)
var mapRegion = MKCoordinateRegionMake(currentCoordinate, mapSpan)
self.mapView.setRegion(mapRegion, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
随着扩展:
extension DetailsViewController: MKMapViewDelegate {
func mapView(mapView: MKMapView!,
viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if annotation …Run Code Online (Sandbox Code Playgroud) 我试图渲染MKMapView成一个UIImage,而不是在屏幕上显示它.我初始化地图:
let mapView = MKMapView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))
mapView.delegate = self
let region = MKCoordinateRegionMakeWithDistance(location.coordinate(), 1000, 1000)
mapView.setRegion(region, animated: false)
Run Code Online (Sandbox Code Playgroud)
我也实现了MKMapKitDelegate这个方法mapViewDidFinishLoadingMap().除非我将地图添加到视图层次结构并使其可见,否则永远不会调用此方法.这意味着,其设置alpha为0,或isHidden到true不工作(在地图中没有加载在这种情况下).救命?
我已经为用户当前位置加载了自定义注释图像.我在后台每1秒后更新当前用户位置.
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[self performSelectorOnMainThread:@selector(tempupdate) withObject:nil waitUntilDone:NO];
[pool release];
-(void)tempupdate
{
NSLog(@"callToLocationManager");
mylocationManager = [[CLLocationManager alloc]init];
NSLog(@"locationManagerM = %@",mylocationManager);
mylocationManager.delegate = self;
mylocationManager.desiredAccuracy = kCLLocationAccuracyBest;
mylocationManager.distanceFilter = 500;
[mylocationManager startUpdatingLocation];
}
Run Code Online (Sandbox Code Playgroud)
更新当前latutude和经度后,我使用以下代码刷新地图
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.002;
span.longitudeDelta=0.002;
CLLocationCoordinate2D location;
location.latitude=[lat doubleValue];
location.longitude=[longt doubleValue];
region.span=span;
region.center=location;
addAnnotation=[[AddressAnnotation alloc]initWithCoordinate:location];
addAnnotation.mTitle=@"You are here";
[self.mapView removeAnnotations:self.mapView.annotations];
[self.mapView addAnnotation:addAnnotation];
[self.mapView setRegion:region animated:TRUE];
[self.mapView regionThatFits:region];
Run Code Online (Sandbox Code Playgroud)
但每次自定义注释图像在添加到地图之前闪烁.如何避免这种闪烁效应?
因为- (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView从缓存加载切片时没有调用,是否有办法知道何时加载了所有切片(从缓存或映射服务器)并显示?
是否有任何代表团暗示瓷砖已装载?
我有一个MKMapView应该使用自定义视图(而不是蓝点)跟踪用户的位置.为了将此视图替换为蓝点,我将其返回:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if (annotation == [mapView userLocation])
{
return userLocationView;
}
}
Run Code Online (Sandbox Code Playgroud)
为了初始化跟踪,我打电话
[mapView setShowsUserLocation: YES];
[mapView setUserTrackingMode: MKUserTrackingModeFollow animated: NO];
[mapView setDelegate: self];
Run Code Online (Sandbox Code Playgroud)
正如预期的那样,-mapView:didUpdateUserLocation:当应用程序加载时会调用一次.不幸的是,除非我-mapView:viewForAnnotation:改为具有以下实现,否则它永远不会被再次调用:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if (annotation == [mapView userLocation])
{
return nil;
}
}
Run Code Online (Sandbox Code Playgroud)
通过这些更改,地图会加载蓝点作为用户位置的指示符,并且-mapView:didUpdateUserLocation:会像预期的那样频繁调用.
是否有某种互斥性来跟踪用户的位置并拥有自定义用户位置视图?我怎么能让两者都发生?
该项目证明了这个问题.https://dl.dropbox.com/u/2338382/MapKitFuckery.zip
这很可能是一个错误,我已将其作为雷达提交.在此期间,接受的答案应该证明是充分的.然而,值得注意的是,我必须完全放弃,[mapView userLocation]并且[mapView showsUserLocation]仅仅支持自定义注释和CLLocationManager.
在Swift 1.2中我有这个:
class UVC: NSViewController, MKMapViewDelegate {
// ...
// **************************************
// MARK: MapView Delegate
// **************************************
func mapView(mapView: MKMapView, rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer! {
if overlay is OSGBTiles {
return OSGBTilesRenderer(tileOverlay: overlay as! OSGBTiles)
} else if overlay is ESRI {
return ESRIRenderer(shapeFileOverlay: overlay as! ESRI)
} else if overlay is MKTileOverlay {
return MKTileOverlayRenderer(overlay: overlay)
} else {
print("Unknown overlay")
}
return nil
}
}
Run Code Online (Sandbox Code Playgroud)
Swift 2已经将定义更改 mapView:rendererForOverlay为现在返回MKOverlayRenderer而不是MKOverlayRenderer!,并且现在不允许我返回nil(不出所料),因为MKOverlayRenderer不是 …
在swift我正在使用MapKit.
我设置了插座@IBOutlet weak var mapView: MKMapView!,使用了MKMapViewDelegate,然后我添加了一些注释.
我想知道是否有可能显示我的地图倾斜并禁用更改它直到用户缩小地图.所以基本上当他放大时 - 从特定的缩放级别到最近的缩放 - 他只会看到:
而不是这个:
并且应该锁定用两个手指滚动来更改此选项.当用户缩小到某个特定的缩放级别(例如,按国家/地区)时,它可以切换到非3D地图.这可以实现吗?
我在以芝加哥为中心的视图中有一张地图。我希望用户能够在地图上放置图钉/注释,然后检索这些坐标。地图加载芝加哥很好,但我无法使注释代码起作用。
我似乎找不到 SwiftUI 的答案,特别是。只有 Swift 和 Storyboards。我觉得我有 99% 的代码,但这些片段不在正确的位置。我包含了错误所在位置的屏幕截图。谢谢你的帮助。
import SwiftUI
import MapKit
struct EntireMapView: UIViewRepresentable {
func updateUIView(_ mapView: MKMapView, context: Context) {
mapView.delegate = context.coordinator
let longPressGesture = UILongPressGestureRecognizer(target: mapView, action: #selector(EntireMapViewCoordinator.addAnnotation(gesture:)))
mapView.addGestureRecognizer(longPressGesture)
let span = MKCoordinateSpan(latitudeDelta: 0.3, longitudeDelta: 0.3)
var chicagoCoordinate = CLLocationCoordinate2D()
chicagoCoordinate.latitude = 41.878113
chicagoCoordinate.longitude = -87.629799
let region = MKCoordinateRegion(center: chicagoCoordinate, span: span)
mapView.setRegion(region, animated: true)
}
func makeUIView(context: Context) -> MKMapView {
let mapView = MKMapView(frame: .zero)
mapView.delegate = context.coordinator
return mapView
} …Run Code Online (Sandbox Code Playgroud) 在我的ios swift应用程序中,我有UITableViewController动态添加的单元格.每个单元都有一个MKMapView嵌入式,我正在为不同坐标上的每个单元设置地图的中心.我这样做是通过调用这个方法:
func centerMapOnLocation(location: CLLocation, map: MKMapView, radius: CLLocationDistance) {
let coordinateRegion = MKCoordinateRegionMakeWithDistance(location.coordinate,
radius * 2.0, radius * 2.0)
map.setRegion(coordinateRegion, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
里面cellForRowAtIndexPath:
override func tableView(tview: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tview.dequeueReusableCellWithIdentifier("cell") as! SingleCall
let user:SingleUser = self.items[indexPath.row] as! SingleUser
let regionRadius: CLLocationDistance = 150
let initialLocation = CLLocation(latitude: user.coordinate.latitude, longitude: user.coordinate.longitude)
centerMapOnLocation(initialLocation, map: cell.eventMap, radius: regionRadius)
cell.eventMap.zoomEnabled = false
cell.eventMap.scrollEnabled = false
cell.eventMap.userInteractionEnabled = false …Run Code Online (Sandbox Code Playgroud) uitableview mapkit mkmapview mkmapviewdelegate mkmapsnapshotter
mkmapview ×9
ios ×5
mapkit ×4
swift ×4
iphone ×2
geolocation ×1
ios10 ×1
ios4 ×1
mkannotation ×1
swiftui ×1
uitableview ×1