我正在使用此函数将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) 我的地图中有两个叠加选项:MKCircleOverlay和MKPolygonOverlay.第一个是可变半径,通过UISlider控制.最后一个是根据角的数量和位置自定义.如果我改变非常快的圆的半径(减少UISlider的值)有时候我的叠加层会消失(圆圈),之后不能再绘制多边形了(当然也是圆圈).没有崩溃的应用程序.可能是什么?
这是我使用的一些代码:
- (IBAction) addCircle:(id)sender
{
slider.hidden = NO;
slider.transform = CGAffineTransformMakeRotation(M_PI*(-0.5));
_longPressRecognizer= [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
_longPressRecognizer.minimumPressDuration = 1.0;
[mapview addGestureRecognizer:_longPressRecognizer];
[_longPressRecognizer release];
}
- (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state != UIGestureRecognizerStateBegan)
return;
CGPoint touchPoint = [gestureRecognizer locationInView:mapview];
CLLocationCoordinate2D touchMapCoordinate = [mapview convertPoint:touchPoint toCoordinateFromView:mapview];
MKPointAnnotation *pa = [[MKPointAnnotation alloc] init];
pa.coordinate = touchMapCoordinate;
pa.title = @"Circle Based Search";
[mapview addAnnotation:pa];
[pa release];
tmC = touchMapCoordinate;
double radius = 1000.0;
self.circleOverlay = [MKCircle circleWithCenterCoordinate:tmC radius:radius];
[mapview removeOverlays:[mapview overlays]];
[mapview addOverlay:circleOverlay]; …Run Code Online (Sandbox Code Playgroud) 在调整NSSlider时,如何在UIMapView上平滑调整MKCircleView的大小?苹果已经成功地做到这一点在查找好友创建地理围栏时,应用程序(http://reviewznow.com/wp-content/uploads/2013/03/find-my-friends-location-alerts-01.jpg),所以我想这在某种程度上是可能的.到目前为止,我已经尝试了以下解决方案,但结果非常"闪烁":
第一次尝试
我添加了一个具有更新半径的新MKCircleView,并在移除滑块更改值后立即移除(如此处建议MKOverlay不能平滑地调整大小).我也尝试过另一种方法:首先删除叠加层,然后添加一个新叠加层,但使用相同的"flickery"结果.
- (void)sliderChanged:(UISlider*)sender
{
double radius = (sender.value * 100);
[self addCircleWithRadius:radius];
[mapView removeOverlays:[self.mapView.overlays firstObject]];
}
Run Code Online (Sandbox Code Playgroud)
第二次尝试
在链接的SO答案中,他建议NSOperation可用于"帮助您更快地创建MKCircle对象",从而在幻灯片更改值时使用上述添加/删除叠加层的方法使调整大小更加平滑.我做了一个实现,每当滑块改变时我就开始一个新的线程.在每个线程中,我删除所有旧的叠加层并添加一个新的叠加层.也许他还有其他一些实现方式,因为我这样做的方式在更改滑块时仍然会出现相同的闪烁.
- (void)sliderChanged:(UISlider*)sender
{
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(updateOverlayWithScale:)
object:[NSNumber numberWithFloat:sender.scale]];
[self.queue addOperation:operation];
}
Run Code Online (Sandbox Code Playgroud)
每个线程运行的方法:
- (void)updateOverlayWithScale:(NSNumber *)scale
{
MKCircle *circle = [MKCircle circleWithCenterCoordinate:self.currentMapPin.coordinate
radius:100*[scale floatValue]];
[self.mapView performSelectorOnMainThread:@selector(removeOverlays:) withObject:self.mapView.overlays waitUntilDone:NO];
[self.mapView performSelectorOnMainThread:@selector(addOverlay:) withObject:circle waitUntilDone:NO];
}
Run Code Online (Sandbox Code Playgroud)
第三次尝试
我还尝试实现我自己的MKOverlayView子类,它根据scale属性绘制自己.每当滑块改变时,我调用setNeedsDisplay并让它自己重绘,但我得到相同的闪烁.
- (void)sliderChanged:(UISlider*)sender
{
self.currentOverlayView.scale = sender.scale
[self.currentOverlayView setNeedsDisplay];
}
Run Code Online (Sandbox Code Playgroud)
而在我的自定义重叠视图我实现drawMapRect:zoomScale:inContext的:(CGContextRef)背景下这样的
- (void)drawMapRect:(MKMapRect)mapRect
zoomScale:(MKZoomScale)zoomScale
inContext:(CGContextRef)context
{
double …Run Code Online (Sandbox Code Playgroud) 我有一个MKMapView,有一个UISearchBar在上面,我希望用户能够键入一个地址,并找到该地址并在其上放置一个图钉.我不知道的是如何将地址字符串转换为经度和纬度,所以我可以创建一个CLLocation对象.有谁知道我怎么做到这一点?
我正在使用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)
这里,显示具有中心坐标的区域.但是,在坐标位置没有绘制点.
如何在该坐标位置绘制点或注释?
我收到以下错误:: initWithPolyline不推荐使用:首先在iOS 7.0中弃用
MKPolylineView *lineView = [[MKPolylineView alloc]
initWithPolyline:overlay];
Run Code Online (Sandbox Code Playgroud)
替代方法的替代方法是什么?
更新2:
这是映射中的现有代码,但它就像注释使用引脚完全无序.一次引脚为绿色,下次运行时,相同的引脚为红色.断开来自哪里?
-(void) viewWillAppear:(BOOL)animated {
self.annotationArray = [[NSMutableArray alloc] init];
CLLocationCoordinate2D coord = {.latitude = 15.8700320, .longitude = 100.9925410};
MKCoordinateSpan span = {.latitudeDelta = 3, .longitudeDelta = 3};
MKCoordinateRegion region = {coord, span};
[mapViewUI setRegion:region];
PFQuery *query = [PFQuery queryWithClassName:@"Share"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
self.mapViewData = objects;
for (int i=0;i<[objects count];i++)
{
// Question * q = [[Question alloc]init];
PFObject * obj = [self.mapViewData objectAtIndex:i];
NSLog(@"%@", obj);
self.theObject = obj;
NSString *string = obj[@"WhereAt"];
NSArray …Run Code Online (Sandbox Code Playgroud) 我在一个项目上使用MKMapView,并希望将地图置于坐标上并放大.就像谷歌地图有:
GMSCameraPosition.camera(withLatitude: -33.8683,
longitude: 151.2086,
zoom: 6)
Run Code Online (Sandbox Code Playgroud)
有没有Mapkit方法呢?
mapkit ×10
ios ×7
mkmapview ×5
iphone ×3
mkoverlay ×2
swift ×2
cllocation ×1
debugging ×1
deprecated ×1
ios4 ×1
mkannotation ×1
mkpolyline ×1
objective-c ×1
uiimage ×1
uikit ×1
xcode ×1