Iphone 将当前位置和另一个位置放置在MKMapKit中。。。。。。

Iphone 将当前位置和另一个位置放置在MKMapKit中。。。。。。,iphone,mkmapview,Iphone,Mkmapview,查询1: 我用的是MKMapKit,我想显示两个位置,一个是当前位置,另一个是固定位置,我用这个代码 - (void)viewDidLoad { mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0,46,320,370)]; [mapView setDelegate:self]; [mapView setShowsUserLocation:TRUE]; [self.view addSubview

查询1: 我用的是MKMapKit,我想显示两个位置,一个是当前位置,另一个是固定位置,我用这个代码

 - (void)viewDidLoad
{
    mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0,46,320,370)];
    [mapView setDelegate:self];
    [mapView setShowsUserLocation:TRUE];    
    [self.view addSubview:mapView];
    [mapView setMapType:MKMapTypeStandard];
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
   [locationManager startUpdatingLocation];
    MKCoordinateRegion region;
    MKCoordinateSpan span;
    span.latitudeDelta=0.9;
    span.longitudeDelta=0.9;
    CLLocationCoordinate2D location=mapView.userLocation.coordinate;
    location.latitude=13.160407;
    location.longitude=80.249562;
    region.span=span;
    region.center=location;
    geoCoder =[[[MKReverseGeocoder alloc] initWithCoordinate:mapView.userLocation.location.coordinate] autorelease];
    geoCoder.delegate = self;
    [geoCoder start];
    [super viewDidLoad];
}
- (MKAnnotationView *)mapView:(MKMapView *)MapView viewForAnnotation:(id<MKAnnotation>)annotation
{
 NSLog(@"View for Annotation is called");

if (NSClassFromString(@"MKUserLocation")==[annotation class]) {
    return nil;
}
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];

annView.pinColor = MKPinAnnotationColorGreen;
UIButton * btn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annView.rightCalloutAccessoryView = btn;
annView.animatesDrop=TRUE;

annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
pindropped = TRUE;
//[map addAnnotations:annotation];
return annView;}
-(void)viewDidLoad
{
mapView=[[MKMapView alloc]initWithFrame:CGRectMake(0,46320370)];
[mapView setDelegate:self];
[地图视图设置显示位置:TRUE];
[self.view addSubview:mapView];
[mapView setMapType:MKMapTypeStandard];
locationManager=[[CLLocationManager alloc]init];
locationManager.delegate=self;
locationManager.desiredAccuracy=KCallocationAccuracyNearesttenmeters;
[locationManager startUpdatingLocation];
协调区域;
Mk坐标跨度;
span.latitudeDelta=0.9;
span.纵向德尔塔=0.9;
CLLocationCoordinate2D location=mapView.userLocation.coordinate;
位置:纬度=13.160407;
位置.经度=80.249562;
地区span=span;
区域。中心=位置;
地理编码器=[[MKReverseGeocoder alloc]initWithCoordinate:mapView.userLocation.location.coordinate]autorelease];
geoCoder.delegate=self;
[地理编码器启动];
[超级视图下载];
}
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释
{
NSLog(@“调用注释视图”);
if(NSClassFromString(@“MKUserLocation”)===[注释类]){
返回零;
}
MKPinAnnotationView*annView=[[MKPinAnnotationView alloc]initWithAnnotation:annotation重用标识符:@“currentloc”];
annView.pinColor=MKPinAnnotationColorGreen;
UIButton*btn=[UIButton Button类型:UIButtonTypedTailExposition];
annView.rightCalloutAccessoryView=btn;
annView.animatesDrop=TRUE;
annView.canShowCallout=是;
annView.calloutOffset=CGPointMake(-5,5);
pindrop=TRUE;
//[地图添加注释:注释];
返回annView;}
我知道这个问题已经被贴了很多次了,但是我找不到任何解决我问题的方法

查询2:
我需要在MPMapKit中绘制两个位置之间的路线(就像在谷歌地图中一样),我该怎么做呢?

1:你忘了你的问题;-)我猜,你看不到你的位置。。。 有两种方法: mapview可以显示您的位置->

mapView.showsUserLocation=YES

或者向地图视图添加注释:

[mapview添加注释:myLocation]

但请阅读mkmapview的文档,您的实现不完整(缺少代理) 再看一看例子


2:不像谷歌地图上的javascript api那么简单。你必须从一点到另一点画线。因此,您需要从google获得准确的路线。

不,我可以看到当前位置(从模拟器)蓝色圆点我找不到固定位置(我在代码中提到了一些坐标),您永远不会将固定位置添加到地图中。使用该位置创建注释并将其添加到地图视图中