如何删除引脚并从离线地图图块中获取当前位置和坐标?

时间:2012-02-20 05:23:48

标签: iphone

请帮助我,我想获得droppin的坐标,并希望获得离线地图图块中的当前位置。这怎么可能?请帮帮我。

4 个答案:

答案 0 :(得分:0)

实施此代码......

-(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;
} 
else {
    [mapView.userLocation setTitle:@"I am here"];
}
return pinView;
}

并且对于当前位置....据我所知,你无法在模拟器中获得当前位置。所以,一个选项是在你的项目中添加.gpx文件。您可以通过使用.gpx进行搜索来添加此内容。设置该文件中的当前位置,lat和lon。这就是我所知道的。我刚刚完成了同样的任务......祝你好运.. :)

答案 1 :(得分:0)

此方法将为您提供所选方法的坐标,上述方法(由Goti提及)是将注释放在所需位置。

 -(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)annotationView
    {   
        if([annotationView class]==[MKAnnotationView class])
        {
            CLLocationCoordinate2D coord = annotationView.annotation.coordinate;        
            NSLog(@"Latitude -> %f",coord.latitude);
                  NSLog(@"Longitude -> %f",coord.longitude);
        }
    }

希望它会有所帮助。

答案 2 :(得分:0)

您不会使用MKMapView在地图中离线获取当前位置。要执行所有任务,请使用cloudmade地图API。

答案 3 :(得分:0)

     MKMapView *locationMap = [[MKMapView alloc] initWithFrame:CGRectMake(0,86, 320, 334)];
        [self.view addSubview:locationMap];
        locationMap.alpha = 1.0;
        locationMap.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
        locationMap.mapType = MKMapTypeStandard;
        locationMap.delegate = self;
        locationMap.showsUserLocation = YES;


- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
    MKAnnotationView *a = [ [ MKAnnotationView alloc ] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
    //  a.title = @"test";
    if ( a == nil )
        a = [ [ MKAnnotationView alloc ] initWithAnnotation:annotation reuseIdentifier: @"currentloc" ];

    NSLog(@"%f",a.annotation.coordinate.latitude);
    NSLog(@"%f",a.annotation.coordinate.longitude);

    CLLocation* currentLocationMap = [[[CLLocation alloc] initWithLatitude:a.annotation.coordinate.latitude longitude:a.annotation.coordinate.longitude] autorelease];
    [self coordinatesToDMS:currentLocationMap];


    MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:a reuseIdentifier:@"currentloc"];
    if(a.annotation.coordinate.longitude == mapView.userLocation.coordinate.longitude ||  a.annotation.coordinate.latitude == mapView.userLocation.coordinate.latitude  )
    {
        if ([annotation isKindOfClass:MKUserLocation.class]) {
            //user location view is being requested,
            //return nil so it uses the default which is a blue dot...
            return nil;
        }       
        //a.image = [UIImage imageNamed:@"userlocation.png"];
        //a.pinColor=;
    }
    else 
    {

        // annView.image =[UIImage imageNamed:@"map-pin.png"];
        //PinFirst=FALSE;
        //annView.pinColor = [UIColor redColor];
        // annView.annotation=annotation;
    }

    annView.animatesDrop = YES;
    annView.draggable = YES;

    annView.canShowCallout = YES;

    return annView;
}