我正在使用此函数将MKMapView实例渲染为图像:
@implementation UIView (Ext)
- (UIImage*) renderToImage
{
UIGraphicsBeginImageContext(self.frame.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
Run Code Online (Sandbox Code Playgroud)
这很好用.但是使用iphone4时,渲染图像的分辨率与设备上的分辨率不同.在设备上我具有640x920地图视图质量,渲染图像具有320x460的分辨率.然后我将提供给UIGraphicsBeginImageContext()函数的大小加倍,但填充了唯一的左上角图像部分.
问题:有没有办法将地图渲染为具有全分辨率640x920的图像?
我正试图抓住触摸事件的坐标.我可以抓住,但是当给变焦有大数字时,我把它放在一个函数中
newCoord = [mapView convertPoint:location toCoordinateFromView:mapView],
Run Code Online (Sandbox Code Playgroud)
我的坐标错了.我能做什么?
我的代码:
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:touch.view];
NSLog(@"locationTOUCH:%f,%f", location.x,location.y);
CLLocationCoordinate2D newCoord;
newCoord = [mapView convertPoint:location toCoordinateFromView:mapView];
NSLog(@"coordinate-%f,%f", newCoord.latitude,newCoord.longitude);
Run Code Online (Sandbox Code Playgroud) 我有一个GLKViewController来处理一些OpenGL绘图.我已经实现了glkView:drawInRect和update方法,并将preferredFramesPerSecond属性设置为30(默认值).
问题是当用户与应用程序的其他部分交互时,委托方法停止触发.我见过这种情况的两种情况是当用户滚动UITableView或与MKMapView交互时.
有没有办法确保这些代表总是触发,无论应用程序的其余部分在做什么.我希望这些停止的唯一时间是应用程序进入后台(这是自动进行).
这是一个奇怪的问题:我的应用程序应该能够调用iOS中的内置地图(包括5.1和6).事实证明它在iOS6下工作得很好,但在iOS5.1下却没有.调用iOS6中的地图,并跟踪从saddr到daddr的路线,但是当我在iOS5中时,地图应用程序被调用,但只有一个引脚放在daddr上.由于某种未知原因,初始坐标(saddr)没有显示,也没有跟踪方向.
这是我的代码:
addr = [NSString stringWithFormat: @"maps://saddr=%f,%f&daddr=%f,%f", newLocation.coordinate.latitude, newLocation.coordinate.longitude, oldLatitude, oldLongitude];
NSURL *url = [NSURL URLWithString:addr];
[[UIApplication sharedApplication] openURL:url];
Run Code Online (Sandbox Code Playgroud)
我尝试将网址更改为"http://maps.google.com/something",但它会调用Safari而不是内置的地图应用.我注意到变量正在正确传递给URL.
有任何想法吗?
提前致谢!
我正在使用storyboard在视图控制器中创建地图视图.
当我使用以下代码时.
-(void) mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
CLLocationDistance distance = 1000;
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate,
distance,
distance);
MKCoordinateRegion adjusted_region = [self.mapView regionThatFits:region];
[self.mapView setRegion:adjusted_region animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
在美国加利福尼亚州旧金山绘制一个点.该
userLocation坐标是预定值MapKit.h框架.现在我创建一个
-(void) mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
CLLocationDistance distance = 1000;
CLLocationCoordinate2D myCoordinate;
myCoordinate.latitude = 13.04016;
myCoordinate.longitude = 80.243044;
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(myCoordinate,
distance,
distance);
MKCoordinateRegion adjusted_region = [self.mapView regionThatFits:region];
[self.mapView setRegion:adjusted_region animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
这里,显示具有中心坐标的区域.但是,在坐标位置没有绘制点.
如何在该坐标位置绘制点或注释?
我正在尝试为MKPolygon制作面积计算类别.我发现了一些JS代码https://github.com/mapbox/geojson-area/blob/master/index.js#L1一个链接的算法:http://trs-new.jpl.nasa.gov/dspace/handle/2014/40409.它说:


这是我的代码,它给出了错误的结果(比实际数千倍):
#define kEarthRadius 6378137
@implementation MKPolygon (AreaCalculation)
- (double) area {
double area = 0;
NSArray *coords = [self coordinates];
if (coords.count > 2) {
CLLocationCoordinate2D p1, p2;
for (int i = 0; i < coords.count - 1; i++) {
p1 = [coords[i] MKCoordinateValue];
p2 = [coords[i + 1] MKCoordinateValue];
area += degreesToRadians(p2.longitude - p1.longitude) * (2 + sinf(degreesToRadians(p1.latitude)) + sinf(degreesToRadians(p2.latitude)));
}
area = area * kEarthRadius * kEarthRadius / 2;
}
return area;
} …Run Code Online (Sandbox Code Playgroud) 我有一个JSON文件,当地图摄像机高度低于750米时,我需要在地图上显示大约2,000个位置.这是我目前的代码:
func addStops() {
var path: String! = NSBundle.mainBundle().pathForResource("stops", ofType: "json")
var jsonData: NSData! = NSData(contentsOfFile: path)
var jsonResult: NSDictionary = NSJSONSerialization.JSONObjectWithData(jsonData, options: NSJSONReadingOptions.MutableContainers, error: nil) as NSDictionary
self.busStops = jsonResult["results"] as NSArray
for (var i = 0; i < self.busStops.count; i++) {
let lat = self.busStops[i]["latitude"] as NSString
let lng = self.busStops[i]["longitude"] as NSString
var annotation = busAnno()
annotation.setCoordinate(CLLocationCoordinate2DMake(CLLocationDegrees(lat.doubleValue), CLLocationDegrees(lng.doubleValue)))
annotation.type = "stop"
self.mapView.addAnnotation(annotation)
}
}
Run Code Online (Sandbox Code Playgroud)
并且注释视图委托:
func mapView (mapView: MKMapView!, viewForAnnotation annotation: MKPointAnnotation!) -> busMarker! {
var pinView …Run Code Online (Sandbox Code Playgroud) 我正在创建一个使用CoreData存储兴趣点的应用程序.MKMapItem坐标可在其中访问mapItem.placemark.location.我想拔出个人纬度和经度坐标并将它们存储在managedObjectContext为double秒.我该怎么办?
我正在尝试使用地图链接api在地图标记上设置标签.根据苹果公司的文档,如果我将'q'参数与'address'参数一起使用,它将把'q'参数作为标签.但我不能让它发挥作用.
Blockquote如果在ll或地址参数文档中明确定义了位置,则q参数也可以用作标签.
这是我试过的网址
http://maps.apple.com/?address=San+Jose&q=Blah
Run Code Online (Sandbox Code Playgroud)
我想让它说'Blah'作为标记的标签.
谢谢.
我在一个项目上使用MKMapView,并希望将地图置于坐标上并放大.就像谷歌地图有:
GMSCameraPosition.camera(withLatitude: -33.8683,
longitude: 151.2086,
zoom: 6)
Run Code Online (Sandbox Code Playgroud)
有没有Mapkit方法呢?