문제

I have gone through certain related answers but dont seem to get correct answer or the answer I need.

As we open googlemap in mkmap view I want to open openstreet map in mkmapview.

If there is any link or sample code showing it please pass it on.

Thanks in advance

도움이 되었습니까?

해결책

MKMapView conforms to Google Map terms and conditions so it uses only google map. You cant integrate OpenStreetMap just like that into MKMapView. Google code has a API RouteME which renders OpenStreetMap in iphone.

RouteMe also provide a good documentation how to include into our project. So feel free to use that.

다른 팁

Import these Frameworks:

#import <MapKit/MapKit.h>

Include this delegate

@interface ViewController () <MKMapViewDelegate>

Add this code to your preexisting viewDidLoad method

(void)viewDidLoad
{
    // Tile system URL template goes here
    NSString *template = @"http://tile.openstreetmap.org/{z}/{x}/{y}.png"; 

    // Associating overlay with URL template
    MKTileOverlay *overlay = [[MKTileOverlay alloc] initWithURLTemplate:template]; 

    // Allowing overlays on MKMapView & disabling Apple map data
    overlay.canReplaceMapContent = YES; 

    // Adding overlay to MKMapView above Apple lables
    [self.mapView addOverlay:overlay level:MKOverlayLevelAboveLabels];

    // Linking the delegate to allow the next method to be called
    self.mapView.delegate = self; 
}

And this somewhere in your class that’s mapView’s delegate (most likely a view controller).

(MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay 
{
    if ([overlay isKindOfClass:[MKTileOverlay class]]) {
        // Overlay the tile with the new template
        return [[MKTileOverlayRenderer alloc] initWithTileOverlay:overlay]; 
    }
    return nil;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top