为了设置外部服务器的查询,我想在我正在构建的iPhone应用程序中获取当前Map View的边界.UIView应该响应边界,但似乎MKMapView没有.设置区域并放大地图后,我尝试获取边界.我坚持第一步,试图获得代表地图SE和NW角落的CGPoints.之后我打算用:
- (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(UIView *)view
Run Code Online (Sandbox Code Playgroud)
将点转换为地图坐标.但我甚至无法做到那么远......
//Recenter and zoom map in on search location
MKCoordinateRegion region = {{0.0f, 0.0f}, {0.0f, 0.0f}};
region.center = mySearchLocation.searchLocation.coordinate;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[self.mapView setRegion:region animated:YES];
//After the new search location has been added to the map, and the map zoomed, we need to update the search bounds
//First we need to calculate the corners of the map
CGPoint se = CGPointMake(self.mapView.bounds.origin.x, mapView.bounds.origin.y);
CGPoint nw = CGPointMake((self.mapView.bounds.origin.x + mapView.bounds.size.width), (mapView.bounds.origin.y + mapView.bounds.size.height)); …Run Code Online (Sandbox Code Playgroud) 我正在尝试捕捉我的点击事件MKMapView,这样我就可以MKPinAnnotation在用户点击的点上删除.基本上我有一个覆盖的地图MKOverlayViews(显示建筑物的叠加层),我想通过删除MKPinAnnotaion并在标注中显示更多信息来为用户提供有关该叠加的更多信息.谢谢.
mkpinannotationview mkmapview ios4 mkoverlay uitapgesturerecognizer
我注意到我的应用程序泄漏了内存,但如果我把MKMapView内存问题消失了.
为了测试这个理论,我做了一个简单的项目,它有一个视图,用一个视图推入一个视图MKMapView并弹出和推动.而已.视图控制器中没有代码,通过故事板完成.
如果我来回地图视图,在推送并弹出带有地图的视图后,它开始大约3MB,大约15倍的内存大约是230MB.
有人见过这个吗?看起来像一个很大的bug.是否有不同的使用方法MKMapView可以防止它泄漏太多?

我试图找出一种方法来获取iOS应用程序上MKMapView上绘制的MKPolyline的所有纬度和经度点.
我知道MKPolyline不存储纬度和经度点,但我正在寻找一种方法来构建一个lat和long数组,MKPolyline会在地图上触摸.
有人在这方面有具体的解决方案吗?
谢谢
编辑:看到第一个响应(谢谢)后,我想我需要更好地解释我的代码在做什么:
就这样.
所以,我已经为我建了一条折线.所以我想以某种方式得到折线中找到的所有点并将它们映射到纬度和长度......
我设法在Swift中获得了注释引脚的自定义图标,但现在我仍然使用2个不同的图像进行不同的注释.现在,按钮会向地图添加注释.应该有另一个按钮,它还添加了注释,但带有另一个图标.
有没有办法使用reuseId?
class ViewController: UIViewController, MKMapViewDelegate {
@IBOutlet weak var Map: MKMapView!
@IBAction func btpressed(sender: AnyObject) {
var lat:CLLocationDegrees = 40.748708
var long:CLLocationDegrees = -73.985643
var latDelta:CLLocationDegrees = 0.01
var longDelta:CLLocationDegrees = 0.01
var span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, longDelta)
var location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(lat, long)
var region:MKCoordinateRegion = MKCoordinateRegionMake(location, span)
Map.setRegion(region, animated: true)
var information = MKPointAnnotation()
information.coordinate = location
information.title = "Test Title!"
information.subtitle = "Subtitle"
Map.addAnnotation(information)
}
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if !(annotation is MKPointAnnotation) …Run Code Online (Sandbox Code Playgroud) 我想为我的自定义MKAnnotationView同步加载图像; 我已经在使用EGOImageView框架了(它与UITableViews非常相似),但是我无法在MKMapView上运行它.图像似乎已加载,但我无法在地图上刷新它们 - [myMap setNeedsDisplay]什么都不做.
当我使用setShowsUserLocation与MKMapView跟踪用户的位置,我该如何设置的准确性和距离过滤器?我不是在谈论CLLocationManager.
谢谢,
更新#5我想这是赏金时间.即使使用我发布的代码示例,也有100多个视图并且没有人被刺穿.一些声望点怎么样!
更新#4这是一个非常复杂的问题,所以我创建了一个新的基于选项卡的项目,其中包含我的应用程序的部分,我在这里遇到了麻烦.您可以从以下网址下载:http://www.servinitup.net/CustomCalloutAnnotation.zip 随意打开它(需要添加自己的包标识符才能在手机上运行)并玩它,看看你是否可以得到那个darned标注注释随着针移动!
更新#3尝试使setAnnotation成为教程的CalloutMapAnnotationView的公共方法并直接调用它.没有运气.尽管发生了一些奇怪的事情,唯一感动的是标注的小三角形部分.我无法让整个标注移动.
更新#2仍然没有多少运气,但现在一直在寻找以编程方式创建"缩放到缩放"然后立即撤消它的方法,因此用户永远不会看到更改.希望以编程方式执行此操作与手动执行此操作具有相同的效果,并且callout注释将弹回到它的父级.有任何想法吗?
更新#1在这里玩了之后我已经得到了: - 替换self.calloutAnnotation.coordinate = coords;为self.calloutAnnotation.latitude = coords.latitude;self.calloutAnnotation.longitude = coords.longitude;
- 随着更改,如果我稍微捏住地图以在引脚更新后放大或缩小,则标注注释会动画到正确的位置,正好在针.
所以现在我需要弄清楚如何在没有用户实际捏缩放的情况下实现这一点.
原帖
我和其他SO用户一起使用这个非常棒的解决方案来创建自定义标注注释:http: //blog.asolutions.com/2010/09/building-custom-map-annotation-callouts-part-1/
当您使用标准标注(annotationview.canShowCallout = true)并且当位置更新时,引脚在屏幕上移动,标准标注随着引脚一起跟踪,就像它们被锁定在一起一样.
使用上面的自定义标注解决方案时,当我的图钉在位置更新后移动时,标注注释将保留在其原始位置.当然,我想模仿iOS标准,并有自定义标注注释轨道和引脚.
这是我到目前为止的代码,它成功地移动了注释视图,但不是自定义的callout注释视图:
/* core location broadcasts a notification, and my view controller listens to that notification and calls locationManagerDidFindLocation */
- (void)locationManagerDidFindLocation:(NSNotification *)notif {
CLLocation *location = [notif.userInfo objectForKey:@"location"];
CLLocationCoordinate2D coords = [location coordinate];
MKCoordinateSpan span = MKCoordinateSpanMake((5/69), (5/69));
MKCoordinateRegion region = … 我有一个数组allCollections,它包含用户通过我的iOS应用程序记录的以编程方式创建的CLLocations数组.allCollections中的每个子数组都包含所有行程中的所有位置点.
我从allCollections中的数组中的CLLocations中绘制MKPolylines来表示MKMapView上的那些行程.我的问题是:将折线添加到地图中,我将如何以编程方式缩放和居中地图以显示所有这些?
在极少数情况下,我的地图上的叠加(小蓝点)会产生奇怪的眩光(右边的大蓝色区域)(如图所示).有时放大或缩小会修复它,但并非总是如此.找不到任何关于为什么会这样的事情.它与渲染方式有关吗?
func drawLocations(_ loc: CLLocation)
{
let center = CLLocationCoordinate2D(latitude: loc.coordinate.latitude, longitude: loc.coordinate.longitude)
let lat: CLLocationDegrees = center.latitude
let long: CLLocationDegrees = center.longitude
var points = [CLLocationCoordinate2DMake(lat,long),CLLocationCoordinate2DMake(lat,long),CLLocationCoordinate2DMake(lat,long),CLLocationCoordinate2DMake(lat,long)]
let polygon = MKPolygon(coordinates: &points, count: points.count)
DispatchQueue.main.async(execute: {
self.mapView.add(polygon)
})
}
func mapView(_ mapView: MKMapView!, rendererFor overlay: MKOverlay!) -> MKOverlayRenderer!
{
if overlay is MKPolygon
{
let polygonView = MKPolygonRenderer(overlay: overlay)
polygonView.lineWidth = 4
polygonView.strokeColor = UIColor(red: 30/255.0, green: 12/255.0, blue: 242/255.0, alpha: 0.4)
return polygonView
}
return nil
}
Run Code Online (Sandbox Code Playgroud) mkmapview ×10
ios ×6
iphone ×5
objective-c ×3
cocoa-touch ×2
mapkit ×2
swift ×2
bounds ×1
cllocation ×1
function ×1
ios4 ×1
ipad ×1
memory-leaks ×1
mkoverlay ×1
mkpolyline ×1
overlay ×1
refresh ×1