Poonam K.
Poonam K.

Reputation: 145

load openstreetmap by using Mapkit framework

I wanted to develop tracking iOS Application , but - I wanted to load openstreetmap by using MapKit framework as Apple map doesn't provide detailed accuracy . - There are so many third party libraries/frameworks i.e. Mapbox,whirlyGlobeMaply, etc. but I dont wanted to use that. as all have pricing plans for commercial level. Also I found that Google Maps also require Pricing at commercial level. - so I have searched for many ways & I found one in following link http://www.glimsoft.com/01/31/how-to-use-openstreetmap-on-ios-7-in-7-lines-of-code/ but it shows multiple tiles - for above code i used url i.e. - "http://tile.openstreetmap.org/10/547/380.png" [which is sample map]. this gives result as follows

Screenshot for openstreetMap tile loading

----- Please give me suggestions, any help will be appriciable. Thanks...

Upvotes: 0

Views: 1879

Answers (1)

PrafulD
PrafulD

Reputation: 568

As per my understanding what you need is; The whole world map in a tile.

Here is a code that I tried in past may be it can help.

Download, TileOverlay.h, TileOverlay.m, TileOverlayView.h, TileOverlayView.m files from Let's Do It

Find View Controller where you manage your MapView object. I assume that your IBOutlet MKMapView is called mapview.

ViewController.h

@interface ViewController : UIViewController <MKMapViewDelegate>


@end

ViewController.m

#import "ViewController.h"
#import "TileOverlay.h"
#import "TileOverlayView.h"

@interface ViewController ()
@property (strong, nonatomic) IBOutlet MKMapView *mapview;
@property (nonatomic, retain) TileOverlay *overlay;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [super viewDidLoad];
    // your existing viewDidLoad code is here

    self.overlay = [[TileOverlay alloc] initOverlay];
    [_mapview addOverlay:self.overlay];
    MKMapRect visibleRect = [_mapview mapRectThatFits:self.overlay.boundingMapRect];
    visibleRect.size.width /= 2;
    visibleRect.size.height /= 2;
    visibleRect.origin.x += visibleRect.size.width / 2;
    visibleRect.origin.y += visibleRect.size.height / 2;
    _mapview.visibleMapRect = visibleRect;
}
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)ovl
{
    TileOverlayView *view = [[TileOverlayView alloc] initWithOverlay:ovl];
    view.tileAlpha = 1.0; // e.g. 0.6 alpha for semi-transparent overlay
    return view;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

Note : The files which you will get have code written with ARC disabled.It is easy to remove them just delete all the retain, release and dealloc

Upvotes: 1

Related Questions