如何根据用户在iPhone上触摸地图上的位置来获取mkmapview中的位置坐标?
我使用自定义MKOverlay通过MKMapView绘制天气数据.该图纸正在CoreGraphics中完成.对于这种特殊情况,仅仅在drawMapRect:zoomScale:inContext:方法中进行绘制是不够的,因为它处理平铺的方式.我需要立即绘制整个图像,而不是像drawMapRect方法那样平铺.
之前,我在.gif中有雷达图像所以我只是添加了一个imageView并在drawMapRect中调整了imageView框架的大小.
我的计划是做一些类似的事情.添加自定义UIView并在drawMapRect中调用setNeedsDisplay.
这是相关的代码.
MKOverlay对象的boundingMapRect属性:
- (MKMapRect)boundingMapRect
{
CLLocationCoordinate2D upperLeftCoord =
CLLocationCoordinate2DMake(weatherData.radarArray.connectedRadar.latitude + 2.5,
weatherData.radarArray.connectedRadar.longitude - 2.5);
MKMapPoint upperLeft = MKMapPointForCoordinate(upperLeftCoord);
CLLocationCoordinate2D lowerRightCoord =
CLLocationCoordinate2DMake(weatherData.radarArray.connectedRadar.latitude - 2.5,
weatherData.radarArray.connectedRadar.longitude + 2.5);
MKMapPoint lowerRight = MKMapPointForCoordinate(lowerRightCoord);
double width = lowerRight.x - upperLeft.x;
double height = lowerRight.y - upperLeft.y;
MKMapRect bounds = MKMapRectMake(upperLeft.x, upperLeft.y, width, height);
return bounds;
}
Run Code Online (Sandbox Code Playgroud)
工作drawMapRect:zoomScale:inContext:代码(太慢了).
- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context {
int numPaths = parser.dataPaths.size();
// We have to pad the map rect a lot to allow for visibility …Run Code Online (Sandbox Code Playgroud) 我想知道是否可以使用Map Kit在地图上仅显示特定区域而不是整个世界地图.就像我想在我的应用程序中显示亚洲地图一样,地图套件隐藏了地图的剩余部分.
我想知道是否有任何方法来配置我们的MapKit地图,就像我们使用Google Maps API中的MapTypeStyle对象一样.
如果我引用Apple doc,MKMapView有一个mapType选项,它使MKMapType保持不变,但没有样式参数,如MapType,MapTypeStyle和MapTypeStyler,对于快速地图自定义非常强大.
所以我的问题是:有没有办法用MapKit框架实现类似的东西,如果没有,那么最好的框架/库是什么?我在想MapBox和类似的产品.
我试图在叠加视图中的两点之间绘制一条直线.在MKOverlayView方法中,我认为我做得正确,但我不明白为什么它没有绘制任何行...
有谁知道为什么?
- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale
inContext:(CGContextRef)context
{
UIGraphicsPushContext(context);
MKMapRect theMapRect = [[self overlay] boundingMapRect];
CGRect theRect = [self rectForMapRect:theMapRect];
// Clip the context to the bounding rectangle.
CGContextAddRect(context, theRect);
CGContextClip(context);
CGPoint startP = {theMapRect.origin.x, theMapRect.origin.y};
CGPoint endP = {theMapRect.origin.x + theMapRect.size.width,
theMapRect.origin.y + theMapRect.size.height};
CGContextSetLineWidth(context, 3.0);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGContextBeginPath(context);
CGContextMoveToPoint(context, startP.x, startP.y);
CGContextAddLineToPoint(context, endP.x, endP.y);
CGContextStrokePath(context);
UIGraphicsPopContext();
}
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助.
目前我正在使用ios mkmapview来显示在地图上添加pin的poi,当用户点击pin时,默认的callout会出现并显示poi的标题,但是有些标题很长而且标注不够宽,无法完全显示标题.我想要的只是让标注更宽,我该怎么做?我搜索了几个小时的答案,但都是关于为callout实现自定义类,有没有办法只是重新调整大小而不进一步实现?我想念一些明显的东西吗?
在VoiceOver下测试时,我的代码在iOS 5下运行良好.我的代码将集合MKPinAnnotationViews到MKMapView.我在iOS 6中的问题是,在到达我添加的引脚之前,画外音会读取街道名称和其他POI(可能很多).有没有办法重新排序这些?我似乎无法找到Apple关于如何为iOS 6的地图添加引脚的任何建议.
谢谢!
我想在a中添加一个公开按钮以MKAnnotation转到另一个视图.
按钮应如下所示:
这是我的.h和.m文件.
//
// POI.h
//
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface POI : NSObject <MKAnnotation> {
NSString *title;
NSString *subtitle;
CLLocationCoordinate2D coordinate;
}
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
- (id)initWithCoordinate:(CLLocationCoordinate2D)_coordinate title:(NSString *)_titolo andSubTitle:(NSString *)_sottotitolo;
@end
Run Code Online (Sandbox Code Playgroud)
//
// POI.m
#import "POI.h"
@implementation POI
@synthesize title, subtitle, coordinate;
-(id)initWithCoordinate:(CLLocationCoordinate2D)_coordinate title:(NSString *)_titolo andSubTitle:(NSString *)_sottotitolo {
[self setTitle:_titolo];
[self setSubtitle:_sottotitolo];
[self setCoordinate:_coordinate];
return self; …Run Code Online (Sandbox Code Playgroud) 我目前正在开发导航应用程序.有没有办法在MapKit中设置视角?我知道谷歌地图iOS SDK将它作为您可以设置的查看相机中的参数之一,但我无法在MapKit中找到它.
关闭3D建筑还有bool价值吗?它们对于导航应用程序来说很烦人.
提前致谢!
在ios上使用普通Map应用时,
当然,您有蓝色的指针按钮,可以在“跟踪”模式之间循环。(显示您自己的位置等)
MKUserTrackingBarButtonItem可以做到这一点,但这是一个愚蠢的条形按钮。我没有酒吧,也不想酒吧,我有一个普通的MKMapView。
我可以使“蓝色箭头按钮”简单地出现在我的MKMapView中(与#$ @栏无关)吗?就像上面的图片一样
或者我可以只使用任何旧的普通按钮,但具有相同的功能吗?
次要的-如果为“ B”,实际上是否有办法获得该蓝色箭头图标?
mapkit ×10
ios ×7
objective-c ×5
iphone ×4
callout ×1
cgcontext ×1
disclosure ×1
google-maps ×1
ios5 ×1
ios6-maps ×1
map ×1
mkannotation ×1
mkmapview ×1
mkoverlay ×1
overlay ×1
voiceover ×1