我试图用特定的图像替换典型的iOS mapkit"pin".我是编码的新手,所以我不确定为什么这不起作用,但这是我尝试过的:
对于该方法
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
Run Code Online (Sandbox Code Playgroud)
除此之外,我还有:
pinView.animatesDrop=YES;
pinView.canShowCallout=YES;
//pinView.pinColor=MKPinAnnotationColorPurple;
UIImage *pinImage = [UIImage imageNamed:@"Jeff.png"];
[pinView setImage:pinImage];
Run Code Online (Sandbox Code Playgroud)
但是,即使代码编译得很好,pinView也没有设置pinImage.任何想法为什么不呢?
我在视图控制器中有MKMapView,当我开始放大时,它消耗了大量内存,当我离开包含MKMapView的视图时,内存未被释放(我在我的应用程序中使用ARC)
编辑:
我读了一些堆栈溢出答案,我必须把MKMapView放在AppDelegate中:
-(MKMapView*) mapView
{
if(_mapView == nil) {
_mapView = [[MKMapView alloc] init];
}
return _mapView;
}
Run Code Online (Sandbox Code Playgroud)
并且在包含MKMapView put的viewController的viewWillDisappear中
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
XAppDelegate.mapView.delegate = nil;
[XAppDelegate.mapView removeFromSuperview];
}
Run Code Online (Sandbox Code Playgroud)
但它没有解决我的问题.
在IOS中我有一个带有几个MKAnnotation的地图,点击其中一个我看到带有文本的气泡,但是文本太长,然后它没有完整显示.
我正在寻找一种在多行TextView或类似的东西中显示文本的方法,以便完全显示.
我正在编写一个使用MapKit的应用程序.我已经实现了MKLocalSearch,我得到了一个MKMapItem数组.但是我想知道是否可以获得这些项目的类别.例如,在地图应用程序中,为商店,酒店,火车站等显示了不同的图标.此外,如果您查看地点标记.您将获得一个类别标签,如Grocery.作为开发人员,我可以访问Map项目的信息吗?如果是这样,我想知道如何.
谢谢
我想实现UISearchController,使用本教程一步一步:
使用MKLocalSearchRequest搜索地点并使用UISearchController显示结果
在本节中......
...我在步骤3中遇到问题.设置表视图数据源
extension LocationSearchTable {
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return matchingItems.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell")!
let selectedItem = matchingItems[indexPath.row].placemark
cell.textLabel?.text = selectedItem.name
cell.detailTextLabel?.text = ""
return cell
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试override从cellForRowAtindexPathtableView函数中删除,在这种情况下我在Xcode中没有错误,但执行后出错:
Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'UITableView (<UITableView: 0x7ff8e03a3800; frame = (0 0; 375 667); clipsToBounds = YES; autoresize = W+H;
gestureRecognizers = <NSArray: …Run Code Online (Sandbox Code Playgroud) 我想使用自定义标记图像而不是脉冲蓝点 - 有没有办法在使用用于 ios 的苹果地图和用于 Android 的谷歌地图的反应原生地图中自定义它?
我已MKUserTrackingButton在地图视图中将 Apple 的新功能添加到我的应用程序中。当用户先前已授予使用位置服务的许可(例如CLAuthorizationStatus.authorizedWhenInUse)时,它可以正常工作。
但是,当用户拒绝权限或权限状态未确定时,用户跟踪按钮会变成活动指示器(又名微调器)并且永不停止旋转。
相反,我想像在 Apple Maps 应用程序中一样显示 iOS 权限警报,或者至少显示某种警报,以向用户提示为什么它不起作用。当然,我也希望活动指示器停止并返回默认的“指南针”图标。
不幸的是,MKUserTrackingButton它不是一个 sublass,UIButton所以我不能向它添加任何目标,而且似乎没有 API 来改变按钮的视觉状态。
知道如何做到这一点吗?
我正在尝试使用 UIKit 设置地图,使用 SF 符号作为注释。到目前为止,一切都很好。
问题是符号是黑色的,我想将颜色更改为白色。
annotationView.image = UIImage(systemName: "23.circle.fill")!.withTintColor(.white, renderingMode: .alwaysTemplate)
Run Code Online (Sandbox Code Playgroud)
不做这项工作。事实上,如果我使用普通的 Pin 图,我就可以改变颜色。
它只是不适用于 SF Symbols。
这是我的代码
annotationView.image = UIImage(systemName: "23.circle.fill")!.withTintColor(.white, renderingMode: .alwaysTemplate)
Run Code Online (Sandbox Code Playgroud)
我还尝试使用以下代码通过 UIImage 扩展更改它:
import SwiftUI
import MapKit
import UIKit
struct MapView: UIViewRepresentable {
func makeUIView(context: Context) -> MKMapView {
let myMapView = MKMapView(frame: .zero)
return myMapView
}
func updateUIView(_ view: MKMapView, context: Context) {
let coordinate = CLLocationCoordinate2D(latitude: 49.289912, longitude: 19.764172)
let span = MKCoordinateSpan(latitudeDelta: 0.027, longitudeDelta: 0.027)
let region = MKCoordinateRegion(center: coordinate, span: span) …Run Code Online (Sandbox Code Playgroud) 我已经使用MapKit实现了 Apple SwiftUI 教程的略微更改版本。
当我运行它时,我收到错误消息并调整我得到的相应视图的大小:
[SwiftUI] NSHostingView is being laid out reentrantly while rendering its SwiftUI content. This is not supported and the current layout pass will be skipped.
查看调用代码:
MapView(coordinate: location?.coordinates)
.frame(minHeight: 200)
.overlay(
GeometryReader{
proxy in
Button("Open in Maps") {
if (self.location?.coordinates != nil){
let destination = MKMapItem(placemark: MKPlacemark(coordinate: self.location!.coordinates))
destination.name = "the car"
destination.openInMaps()
}
}
.frame(width: proxy.size.width, height: proxy.size.height, alignment: .bottomTrailing)
.offset(x: -10, y: -10)
}
)
Run Code Online (Sandbox Code Playgroud)
地图视图结构:
import SwiftUI
import MapKit
/// a …Run Code Online (Sandbox Code Playgroud) 我使用 MKLocalSearchCompleter搜索地点,并在选择 tableView 单元格时优化结果。当选择 MKLocalSearchCompletion 并启动 MKLocalSearch.Request() 时,我收到以下错误(示例选择洛杉矶):\n根据我的研究,这是一个非常罕见的问题?!
\n这些是 TableViewController 中的实例变量:
\nvar searchCompleter = MKLocalSearchCompleter()\nvar searchResults = [MKLocalSearchCompletion]()\nRun Code Online (Sandbox Code Playgroud)\n每次更改搜索词时都会运行此代码:
\nsearchCompleter.queryFragment = text\nsearchCompleter.resultTypes = .address\nsearchCompleter.region = region\nRun Code Online (Sandbox Code Playgroud)\n在 tableView \xe2\x80\xa6 didSelectRowAt\xe2\x80\xa6 中执行以下代码:
\nlet selectedItem = searchResults[indexPath.row]\n \nlet searchRequest = MKLocalSearch.Request()\nsearchRequest.naturalLanguageQuery = selectedItem.title\nsearchRequest.resultTypes = .address\n \nlet search = MKLocalSearch(request: searchRequest)\nsearch.start { …Run Code Online (Sandbox Code Playgroud) mapkit ×10
ios ×6
swift ×5
objective-c ×3
mkmapview ×2
swiftui ×2
annotations ×1
attribution ×1
cocoa ×1
google-maps ×1
ipad ×1
macos ×1
mkmapitem ×1
sf-symbols ×1
uikit ×1