2012-02-20 67 views
1

请帮我,我想获取droppin的坐标,并且还想获取离线地图图块中的当前位置。这怎么可能?请帮帮我。如何放置图钉并从离线地图图块中获取当前位置和坐标?

+0

为什么在这个问题上减点?如果你知道的话请告诉我? – 2012-02-20 05:29:52

+0

那些谁是专家,他们发现这个问题很愚蠢,所以他们中的一个可能会减少你的分数。 – HarshIT 2012-02-20 06:01:48

+1

如果这是肮脏的问题,那么为什么没有人能够给出答案? – 2012-02-20 06:10:06

回答

0

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

+0

不错的云找地图API =) – henghonglee 2012-02-20 06:19:37

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。这就是我所知道的。我刚刚完成了相同的任务...祝你好运.. :)

+0

你好,但我想要在离线地图中不是在Mapview中做到这一点。我有地图图块和我想放下图钉的图块。 – 2012-02-20 06:00:07

+0

您需要详细说明您的离线地图,以及互联网连接的程度,如果mapview不是您需要的,您可能必须自行完成坐标计算。 – henghonglee 2012-02-20 06:18:52

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); 
     } 
    } 

希望它会有帮助。

+0

但我离线地图瓷砖没有mapview。 – 2012-02-20 06:06:31

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; 
} 
相关问题