0

我使用MKMapView创建了一个地图视图。一切正常,但我得到的地图和我应该得​​到的地图有所不同。在我看来,地图即将到来,但我猜不正确。请看看区别,让我知道是什么问题。谢谢这是我的ViewController.m

#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

视图控制器.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

我得到以下地图

在此处输入图像描述

我应该得到以下地图

在此处输入图像描述

4

1 回答 1

0

当我将你使用的坐标输入谷歌地图时,我会去你所看到的同一个地方,而不是你认为你“应该”去的地方。你确认坐标了吗?你认为你应该去的花边的坐标是多少?

这是两个地方之间的路线http://goo.gl/maps/TrM3q

根据 Goolge 的说法,您希望 iOS 应该距离您正在使用的坐标约 2000 公里,这不会发生。

于 2013-03-12T22:21:06.273 回答