2013-03-12 37 views
0

我創建了一個mapview使用MKMapView。一切工作正常,但是我得到的地圖和我應該得​​到的地圖有所不同。在我看來,地圖即將到來,但我猜不正確。請查看差異並讓我知道是什麼問題。 感謝 這裏是我的ViewController.m沒有得到正確的地圖使用MKMapVIew

#import "ViewController.h" 
@interface ViewController() 
@end 
@implementation ViewController 


- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
mapView=[[MKMapView alloc]initWithFrame:CGRectMake(0, 0, 320, 400)]; 
mapView.delegate=self; 
[mapView setMapType:MKMapTypeStandard]; 
[mapView setZoomEnabled:YES]; 
[mapView setScrollEnabled:YES]; 

MKCoordinateRegion region = { {0.0, 0.0},{0.0,0.0}}; 
region.center.latitude = 12.9667; 
region.center.longitude = 77.5833; 
region.span.longitudeDelta = 0.01f; 
region.span.latitudeDelta = 0.01f; 
[mapView setRegion:region animated:YES]; 
[self.view addSubview:mapView]; 

DisplayMap *annotation = [[DisplayMap alloc]init]; 
annotation.title = @" Bangalore"; 
annotation.subtitle = @"Silver Jublee Park"; 
annotation.coordinate = region.center; 
[mapView addAnnotation:annotation]; 
} 


-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation: 

(id <MKAnnotation>)annotation 
    { 
MKPinAnnotationView *pinView = nil; 
if(annotation != mapView.userLocation) 

{ 
     static NSString *defaultPinID = @"com.invasivecode.pin"; 
     pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID]; 
     if (pinView == nil) pinView = [[[MKPinAnnotationView alloc] 
             initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease]; 
    pinView.pinColor = MKPinAnnotationColorRed; 
    pinView.canShowCallout = YES; 
    pinView.animatesDrop = YES; 
} 
    return pinView; 
} 


- (void)didReceiveMemoryWarning 
{ 
[super didReceiveMemoryWarning]; 
} 
@end 

@implementation DisplayMap 
@synthesize coordinate,title,subtitle; 
-(void)dealloc{ 
[title release]; 
[subtitle release]; 
[super dealloc]; 
} 
@end 

ViewController.h

#import <UIKit/UIKit.h> 
#import <MapKit/MapKit.h> 
@interface ViewController : UIViewController<MKMapViewDelegate> { 
MKMapView *mapView; 
} 
@end 


@class DisplayMap; 
@interface DisplayMap : NSObject <MKAnnotation> { 
CLLocationCoordinate2D coordinate; 
NSString *title; 
NSString *subtitle; 
} 
@property (nonatomic, assign) CLLocationCoordinate2D coordinate; 
@property (nonatomic, copy) NSString *title; 
@property (nonatomic, copy) NSString *subtitle; 
@end 

我正在以下地圖

enter image description here

我應該得到的followi NG地圖

enter image description here

+0

你知道鍵盤上的''鍵嗎? – 2013-03-12 07:01:30

+0

是的,我知道。爲什麼? – Newbee 2013-03-12 07:05:03

+0

查看您發佈的代碼中第一種方法的實現。它的格式非常糟糕,由於完全沒有任何縮進,所以很難閱讀。 – 2013-03-12 07:06:29

回答

0

當我把你使用到谷歌地圖,我去,你所看到的同一個地方的座標,有不對的地方,你想你「應該」獲得。你是否驗證過座標?你認爲你應該去的蕾絲的座標是什麼?

這裏有兩個地方http://goo.gl/maps/TrM3q

之間的路由根據Goolge的您所期待的iOS到應該的地方〜2000公里從你使用的是coordiantes,這是不會發生的路程。

+0

我不會在地方的座標之間混淆。我知道那兩個是不同的地方。你能否看到地圖顯示方式的差異。我得到的地圖不像正確的谷歌地圖,事實上你也不能在我的地圖上看到Google徽標。但是當相同的項目在其他系統中運行時,它會顯示正確的Google地圖。請不要看到座標。我的困惑是關於地圖的顯示方式。 – Newbee 2013-03-13 05:08:13

+1

然後你需要在原始問題中更清楚地解釋你自己。您剛剛提供了兩張圖片,並且說A不像B. 應該是常識,自iOS6以來,Apple一直在使用他們自己的地圖,而不是Google的。你所看到的是這樣的後果。如果你在iOS5上運行你的應用,你會看到Google的地圖。 如果您確實想要Google Base圖查看他們的API http://code.google.com/p/google-api-objectivec-client,但是在使用MKMapView時,您必須將地圖蘋果公司給你,或者讓你自己超越頂端。 – Craig 2013-03-13 17:24:49

+0

感謝哥們。其實我也檢查了ios5和ios6,並且知道ios5默認情況下它會是谷歌地圖,但是在ios6中它不是那樣的。由於我使用的是ios6,所以我的地圖不同。對不起,打擾你這麼多人。 – Newbee 2013-03-14 11:39:42