我已经设置了一个用于Google Maps JavaScript API的磁贴源.我试图将其翻译为与iPhone MapKit一起使用.我已经正确地将javascript缩放级别实现到mapkit中.无论何时- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated调用,我都会根据相同的中心点将区域捕捉到最近的缩放级别.
是否可以使用CATiledLayer实现解决方案来实现切片解决方案.iPhone是否使用标准的256x256瓷砖,如谷歌地图本身?任何方向或帮助将非常感谢.如果不可能的话,我宁愿不浪费几个星期试图实现这个.
如果用户缩小MKMapView,我希望彼此接近的MKAnnotations自动分组为一个"组"注释.如果用户缩放,则应将"组"注释再次拆分为唯一/原始注释.
苹果已经在iOS 4 Photos.app中做到了这一点
是否有一种常见的"预定义"方式来做到这一点?
快速了解我的情况.UIMapView加载并显示单个注释(从不多于一个).在菜单栏上,有一个Locate Me按钮,点击查找userLocation并显示为第二个注释.然后我将MapView缩小以适应范围内的那些注释,但我无法找到合适的方法.根据第一个注释相对于用户位置的位置,有时它不会缩小.
例如,如果注释位于用户的西北方向,则会缩小范围.但是如果注释是用户的东南方,它只会缩小到足以让它们被切断,你必须手动缩小一点.这是我正在使用的代码,我在SO上找到的其他一些代码的变体.
CLLocation *whereIAm = mapView.userLocation.location;
float lat = whereIAm.coordinate.latitude;
float lon = whereIAm.coordinate.longitude;
CLLocationCoordinate2D southWest = {[currentLatitude floatValue], [currentLongitude floatValue]};
CLLocationCoordinate2D northEast = southWest;
southWest.latitude = MIN(southWest.latitude, lat);
southWest.longitude = MIN(southWest.longitude, lon);
northEast.latitude = MAX(northEast.latitude, lat);
northEast.longitude = MAX(northEast.longitude, lon);
CLLocation *locSouthWest = [[CLLocation alloc] initWithLatitude:southWest.latitude longitude:southWest.longitude];
CLLocation *locNorthEast = [[CLLocation alloc] initWithLatitude:northEast.latitude longitude:northEast.longitude];
CLLocationDistance meters = [locSouthWest distanceFromLocation:locNorthEast];
MKCoordinateRegion region;
region.center.latitude = (southWest.latitude + northEast.latitude) / 2.0;
region.center.longitude = (southWest.longitude + northEast.longitude) / 2.0;
region.span.latitudeDelta = meters …Run Code Online (Sandbox Code Playgroud) 我一直在关注Apple的iOS类参考文档,不幸的是,没有人更明智.我已经下载了他们的示例代码,KMLViewer但是他们已经过于复杂了...我真正想知道的是如何生成路径并将其添加到MKMapView.文档讨论了使用a CGPathRef,但没有真正解释如何.
现在需要帮助.我可以用MKPolyline和MKPolylineView绘制线条,但是如何在MKMapView上的两个坐标之间绘制弧线或曲线?十分感谢.
最终的解决方案
最后,我在这里写下了这些结论,以帮助谁想要它.
如果你想:
所以解决方案是:
这里有一些提示:
当我尝试显示地图时,我得到了这个例外:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid Region <center:+inf, +0.00000000 span:+1.00000000, +0.50000000>'
Run Code Online (Sandbox Code Playgroud)
我的相关代码是这样的:
-(void)viewWillAppear:(BOOL)animated
{
[mapView removeAnnotations:mapView.annotations];
// locationManager update as location
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
//Configure the new event with information from the location
CLLocationCoordinate2D coordinate = [location coordinate];
latitudeOfUserLocation=coordinate.latitude;
longitudeOfUserLocation=coordinate.longitude;
location2D = (CLLocationCoordinate2D){ .latitude = latitudeOfUserLocation, .longitude = longitudeOfUserLocation };
MyLocation *annotation=[[[MyLocation alloc]initWithName:@"You are here" distanceVersLaStation:@"" coordinate:location2D]autorelease];
annotation.pinColor …Run Code Online (Sandbox Code Playgroud) 我有两点的纬度和经度,并希望在MapKit上使用Pin在这两点之间画线.
我用谷歌搜索但找不到合适的解决方案,因为我找到的是用数据点数组绘制叠加层,但我在这两点之间没有任何点数.
只需两点,并希望在这两点之间画线.
请帮忙.
我有一个工作循环来为一些工作数据点的标题和副标题元素设置注释.我想在同一个循环结构中做的是将引脚颜色设置为紫色而不是默认值.我无法弄清楚我需要做些什么来点击我的theMapView来相应地设置引脚.
我的工作循环和一些尝试......
....
for var index = 0; index < MySupplierData.count; ++index {
// Establish an Annotation
myAnnotation = MKPointAnnotation();
... establish the coordinate,title, subtitle properties - this all works
self.theMapView.addAnnotation(myAnnotation) // this works great.
// In thinking about PinView and how to set it up I have this...
myPinView = MKPinAnnotationView();
myPinView.animatesDrop = true;
myPinView.pinColor = MKPinAnnotationColor.Purple;
// Now how do I get this view to be used for this particular Annotation in theMapView that I am iterating through??? …Run Code Online (Sandbox Code Playgroud) 我想将Legal标签移到右侧.在iOS 6和7上,下面的解决方案工作正常,但是在iOS 8.3上似乎不起作用.
我得到了标签,然后用计时器(0.1秒)viewDidLayoutSubviews我调用这个方法:
-(void)moveLegalLabel
{
UIView * legalLink = [self attributionView];
legalLink.frame = CGRectMake(self.mapView.frame.size.width - legalLink.frame.size.width - 10, self.mapView.frame.size.height - legalLink.frame.size.height - 10 , legalLink.frame.size.width, legalLink.frame.size.height);
legalLink.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin;
}
Run Code Online (Sandbox Code Playgroud)
它可以很好地用于旋转等.但是一旦我滚动地图,标签就会跳回到左边.试图在这个方法中调用这个方法,regionDidChangeAnimated但是标签首先向左跳,然后向右跳,这真的很烦人......
我怎么能强迫那个愚蠢的标签留在右侧?
Christian建议的解决方案:
moveLegalLabel代码移到那里layoutSubviews-(void)layoutSubviews
{
[super layoutSubviews];
[self moveLegalLabel];
}
使用Swift5.7、XCode14.0、iOS16.0、
当尝试使 MapKit 示例正常工作时,我在 XCode 控制台中收到非常奇怪的错误消息和警告。
这是日志:
2022-11-01 17:26:51.756834+0100 myApp[3999:834036] Metal API Validation Enabled
2022-11-01 17:26:52.139973+0100 myApp[3999:834036] [PipelineLibrary] Mapping the pipeline data cache failed, errno 22
2022-11-01 17:26:52.192482+0100 myApp[3999:834036] [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)""
2022-11-01 17:26:53.884031+0100 myApp[3999:834036] [SwiftUI] Publishing changes from within view updates is not allowed, this will cause undefined behavior.
2022-11-01 17:26:53.900265+0100 myApp[3999:834036] [SwiftUI] Publishing changes from within view updates is not allowed, this will cause undefined behavior.
Run Code Online (Sandbox Code Playgroud)
看来在 SwiftUI 中,发布的变量与绑定的处理方式发生了变化。
我认为,这里很好地描述了核心问题。
我认为 …
mapkit ×10
ios ×7
iphone ×6
mkmapview ×6
objective-c ×3
ipad ×2
swift ×2
annotations ×1
catiledlayer ×1
cgpath ×1
cocoa-touch ×1
ios8 ×1
mkannotation ×1
swiftui ×1
zoom ×1