我使用 MapKit.js 创建了以下地图,其中包含数百个自定义注释、聚类(黄点)和单击注释时弹出的标注。
当单击弹出链接时,我想要做的只是放大一步并在单击的注释上居中视图(在响应式上下文中)。
在我习惯的谷歌地图中,您只需通过地图的中心和缩放级别来定位地图即可。
在 MapKit.js 中,您使用中心/区域组合,老实说我无法理解它是如何工作的。
我不清楚官方文档,而且我无法找到真正有启发性的资源。
如果有人可以向我解释我们应该如何使用中心/区域组合来管理缩放级别,我将非常感激。
谢谢 :-)
[编辑]
这个中心/区域的事情对我来说仍然没有意义,所以我决定用缩放功能覆盖 MapKit.js。
感谢这篇文章,我成功地实现了缩放计算,这似乎没问题。
我现在需要实现设置的缩放操作。
还没有成功,这个数学的事情到现在为止^^
非常欢迎任何帮助:-)
功能:
function MapKitJsZoom(map) {
var LN2 = 0.6931471805599453; // ???
var WH = 256; // World Height
var WW = 256; // World Width
var MAX = 21; // Max zoom level
// GET CURRENT ZOOM.
var latToRad = function (lat) {
var sin = Math.sin(lat * Math.PI / 180);
var radX2 = Math.log((1 + sin) / (1 - …Run Code Online (Sandbox Code Playgroud) 我有一个 CLLocationCooperative2D 数组,需要绘制一条从数组中的第一个索引到最后一个索引的线。
我已经在这里和其他地方看到了答案,但它们主要适用于较旧版本的 swift,或者适用于首先转换为双精度数或其他任何值的字符串数组,或者仅适用于单个位置。
我尝试创建 MKPolyline、viewForOverlay 等,但无法显示该线。我缺少什么?
let locationManager = CLLocationManager()
let regionRadius: CLLocationDistance = 3000
var locations: [CLLocationCoordinate2D] = []
var latitude: [CLLocationDegrees] = []
var longitude: [CLLocationDegrees] = []
override func viewDidLoad() {
super.viewDidLoad()
mapView.delegate = self
mapView.register(MKMarkerAnnotationView.self, forAnnotationViewWithReuseIdentifier: MKMapViewDefaultAnnotationViewReuseIdentifier)
createAnnotations()
centerMapOnLocation(location: initialLocation)
var polyline = MKPolyline(coordinates: &locations, count: locations.count)
mapView.addOverlay(polyline)
}
// MARK: - Create Annotaions
func createAnnotations() {
locations = zip(latitude, longitude).map(CLLocationCoordinate2D.init)
AppLogger.logInfo("\(locations)")
for location in locations {
let annotation = MKPointAnnotation()
annotation.coordinate = CLLocationCoordinate2D(latitude: …Run Code Online (Sandbox Code Playgroud) 我想使用自己的地图注释,并且试图隐藏地图中的默认注释。
我发现这可以从地图视图中删除每个默认注释
let configuration = MKStandardMapConfiguration()
configuration.pointOfInterestFilter = MKPointOfInterestFilter(including: [])
Run Code Online (Sandbox Code Playgroud)
但如何将此配置应用于 SwiftUI 中的地图视图?
import SwiftUI
import MapKit
@available(iOS 16.0, *)
struct MyMapView: View {
init (){
let configuration = MKStandardMapConfiguration()
configuration.pointOfInterestFilter = MKPointOfInterestFilter(including: [])
}
@State private var region = MKCoordinateRegion(
center: CLLocationCoordinate2D(
latitude: 41.59710,
longitude: -74.14976),
span: MKCoordinateSpan(
latitudeDelta: 0.0125,
longitudeDelta: 0.0125)
)
var body: some View {
Map(coordinateRegion: $region)
.edgesIgnoringSafeArea(.all)
.disabled(true)
}
}
Run Code Online (Sandbox Code Playgroud) 我正在向MapView添加几个注释并使用自定义图像而不是默认图钉.我正在使用viewForAnnotation委托方法来设置自定义图像,如下所示:
view.image = [UIImage imageNamed:@"placemark.png"];
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
[(MKPinAnnotationView *)view setImage:[UIImage imageNamed:@"placemark.png"]];
Run Code Online (Sandbox Code Playgroud)
现在,这些都将图像设置得很好.但是,当点击注释或mapType更改为卫星或混合时,它会重置为红色图钉.我错过了什么?
我有我的所有注释安装到屏幕的问题......有时它会显示所有注释,但另外一些时候应用在两个注释之间放大,使他们都不是可见的.我希望应用程序始终使区域适合注释而不是放大它们之间...我做错了什么?
if ([mapView.annotations count] == 2) {
CLLocationCoordinate2D SouthWest = location;
CLLocationCoordinate2D NorthEast = savedPosition;
NorthEast.latitude = MAX(NorthEast.latitude, savedPosition.latitude);
NorthEast.longitude = MAX(NorthEast.longitude, savedPosition.longitude);
SouthWest.latitude = MIN(SouthWest.latitude, location.latitude);
SouthWest.longitude = MIN(SouthWest.longitude, location.longitude);
CLLocation *locSouthWest = [[CLLocation alloc] initWithLatitude:SouthWest.latitude longitude:SouthWest.longitude];
CLLocation *locNorthEast = [[CLLocation alloc] initWithLatitude:NorthEast.latitude longitude:NorthEast.longitude];
CLLocationDistance meter = [locSouthWest distanceFromLocation:locNorthEast];
MKCoordinateRegion region;
region.span.latitudeDelta = meter / 111319.5;
region.span.longitudeDelta = 0.0;
region.center.latitude = (SouthWest.latitude + NorthEast.latitude) / 2.0;
region.center.longitude = (SouthWest.longitude + NorthEast.longitude) / 2.0;
region = [mapView regionThatFits:region];
[mapView setRegion:region …Run Code Online (Sandbox Code Playgroud) 我想知道是否有人有关于Google Maps API的文档,我只是在寻找我想在我的iOS应用程序上实现它的流量实时信息.
这样的API是否存在?
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
self.mapView.frame = self.view.bounds;
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
CLLocationCoordinate2D startCoord = CLLocationCoordinate2DMake(36.7472, -95.9594);
MKCoordinateRegion adjustedRegion = [self.mapView regionThatFits:MKCoordinateRegionMakeWithDistance(startCoord, 10000*1609.344, 10000*1609.344)];
[self.mapView setRegion:adjustedRegion animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
这就是我现在的代码.当我将iPad的方向从横向更改为纵向时,地图视图的大小不会更改.我希望它能填满整个视图.我试过搜索谷歌和stackoverflow的解决方案,但我没有运气.
任何帮助都会非常感激.
MKMapView滚动视图时,我一直在记录相机的高度,但我发现了一个奇怪的现象:尽管地图的缩放级别外观保持不变,但视点的高度却随着用户的滚动而波动。
仔细检查后,似乎随着用户向南滚动(向着赤道),海拔降低,一旦用户经过赤道,海拔又再次升高。我认为这可能与地球曲率有关,并且可能涉及一些我没有的三角学或制图学知识。
我正在尝试模拟此功能。我有一个CLLocationCoordinate2D和当前高度和缩放级别,我想计算的正确高度MKMapCamera。
谢谢!
我正在添加一个这样的callout视图:
func mapView(mapView: MKMapView!,
didSelectAnnotationView view: MKAnnotationView!) {
let calloutView = UIView(frame:
CGRect(x: 0, y: 0, width: 300, height: 120))
calloutView.backgroundColor = UIColor.purpleColor()
calloutView.center = CGPointMake(CGRectGetWidth(view.bounds) / 2.0, 0.0)
calloutView.layer.anchorPoint = CGPointMake(0.5, 1.0)
calloutView.layer.masksToBounds = false
calloutView.userInteractionEnabled = true
let calloutViewTapRecognizer = UITapGestureRecognizer(target: self,
action: "onCalloutViewTap")
calloutView.addGestureRecognizer(calloutViewTapRecognizer)
view.addSubview(calloutView)
}
Run Code Online (Sandbox Code Playgroud)
虽然我的onCalloutViewTap函数从未被调用过......但我很想知道为什么以及能够处理与我的标注视图交互的东西.
mapkit ×10
ios ×4
mkmapview ×4
iphone ×3
swift ×3
swiftui ×2
cocoa-touch ×1
javascript ×1
mkannotation ×1
mkpolyline ×1
orientation ×1
resize ×1
traffic ×1