MapKit中的MapTypeStyle

我想知道是否有任何方法来configuration我们的MapKit地图,就像我们在Google Maps API中使用MapTypeStyle对象一样。

如果我参考苹果文件,MKMapView有一个mapType选项, MKMapType常量,但没有像MapOptions的MapTypeStyle和MapTypeStyler风格参数,这是非常强大的快速地图定制。

所以我的问题是:有没有什么办法可以实现与MapKit框架相似的东西,如果没有,最好的框架/库是做什么的? 我正在考虑MapBox和类似的产品。

你的朋友有几种select。 你可以使用这些框架之一

http://cloudmade.com/products/iphone-sdk

https://github.com/route-me/route-me

或者你可以使用mapbox。 他们的api看起来不错。 或者,您可以提供自己的地图图块和覆盖图mapkit。 在MKOverlayView中是这样的

- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context { NSURL* fileURL = [(HeatMap*)self.overlay localUrlForStyle:@"alien" withMapRect:mapRect andZoomScale:zoomScale]; NSData *imageData = [NSData dataWithContentsOfURL:fileURL ]; if (imageData != nil) { UIImage* img = [UIImage imageNamed:@"aTileX.png"]; // Perform the image render on the current UI context UIGraphicsPushContext(context); [img drawInRect:[self rectForMapRect:mapRect] blendMode:kCGBlendModeNormal alpha:1.0]; UIGraphicsPopContext(); } } 

如果你想要不受支持的“地形”模式http://openradar.appspot.com/9621632,请检查这一点

我实际上是在一个需要在地图上覆盖瓦片的程序的中间。 这个例子非常有帮助。 你会想看看MKOverlay和MKOverlayView。 我正在做的项目涉及使用gheat 。 我通过NSURLConnection访问磁贴并将它们存储在本地。 我的实现的要点 。

没有办法用mapkit本地化地图样式。 您唯一的select是select混合应用程序方法,然后在页面中使用html / javascript自定义样式。

由于在一个名为MKMapTileView的私有类中绘制图块,您不能简单地编写一个类别。 您必须为自定义绘图实现另一个类。 这个类的方法将被用于在运行时重载MKMapTileView的实现:

头文件:

 @interface MyColorMap : NSObject + (void)overLoadMethods:(Class)destinationClass; @end 

Imlementation:

 #import "MyColorMap.h" #import <objc/runtime.h> @implementation MyColorMap + (void)overLoadMethods:(Class)destinationClass { // get the original method for drawing a tile Method originalDrawLayer = class_getInstanceMethod(destinationClass, @selector(drawLayer:inContext:)); // get the method we will replace with the original implementation of 'drawLayer:inContext:' later Method backupDrawLayer = class_getInstanceMethod([self class], @selector(backupDrawLayer:inContext:)); // get the method we will use to draw our own colors Method myDrawLayer = class_getInstanceMethod([self class], @selector(myDrawLayer:inContext:)); // dito with the implementations IMP impOld = method_getImplementation(originalDrawLayer); IMP impNew = method_getImplementation(myDrawLayer); // replace the original 'drawLayer:inContext:' with our own implementation method_setImplementation(originalDrawLayer, impNew); // set the original 'drawLayer:inContext:' implementation to our stub-method, so wie can call it later on SEL selector = method_getName(backupDrawLayer); const char *types = method_getTypeEncoding(backupDrawLayer); class_addMethod(destinationClass, selector, impOld, types); } - (void)backupDrawLayer:(CALayer*)l inContext:(CGContextRef)c { // stub method, implementation will never be called. The only reason we implement this is so we can call the original method durring runtime } - (void)myDrawLayer:(CALayer*)l inContext:(CGContextRef)c { // set background to white so wie can use it for blendmode CGContextSetFillColorWithColor(c, [[UIColor whiteColor] CGColor]); CGContextFillRect(c, CGContextGetClipBoundingBox(c)); // set blendmode so the map will show as grayscale CGContextSetBlendMode(c, kCGBlendModeLuminosity); // kCGBlendModeExclusion for inverted colors etc. // calling the stub-method which will become the original method durring runtime [self backupDrawLayer:l inContext:c]; // if you want more advanced manipulations you can alter the context after drawing: // int w = CGBitmapContextGetWidth(c); // int h = CGBitmapContextGetHeight(c); // // unsigned char* data = CGBitmapContextGetData(c); // if (data != NULL) { // int maxY = h; // for(int y = 0; y<maxY; y++) { // for(int x = 0; x<w; x++) { // // int offset = 4*((w*y)+x); // char r = data[offset]; // char g = data[offset+1]; // char b = data[offset+2]; // char a = data[offset+3]; // // // do what ever you want with the pixels // // data[offset] = r; // data[offset+1] = g; // data[offset+2] = b; // data[offset+3] = a; // } // } // } } 

现在你必须在使用MKMapView之前调用[MyColorMap overLoadMethods:NSClassFromString(@"MKMapTileView")]