簡體   English   中英

想要在地圖上顯示具有用戶更新位置的自定義圖像

[英]Want to show custom images on the map with user update location

我想在Google地圖上以用戶遵循的旋轉方式顯示自行車/汽車圖像。 怎么可能。 我添加了didUpdateToLocation方法來更新用戶的位置,並添加了viewForAnnotation以顯示自行車的當前位置。 但無法在用戶遵循的地圖上顯示自行車。

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation *)oldLocation
{
    CLLocation *currentLocation = newLocation;
    if(currentLocation != nil)
    {
        CLLocationCoordinate2D location = CLLocationCoordinate2DMake(currentLocation.coordinate.latitude,currentLocation.coordinate.longitude);
         MyAnnotation *annotation = [[MyAnnotation alloc] initWithCoordinates:location title:@"India" subTitle:@"Sarvopari Mall"];
        [self.myMapView addAnnotation:annotation];
    }
}


- (MKAnnotationView *)mapView:(MKMapView *)mapView
            viewForAnnotation:(id <MKAnnotation>)annotation{

    MKAnnotationView *result = nil;

    if ([annotation isKindOfClass:[MyAnnotation class]] == NO)
    {
        return result;
    }

    if ([mapView isEqual:self.myMapView] == NO)
    {
        return result;
    }

    MyAnnotation *senderAnnotation = (MyAnnotation *)annotation;

    NSString *pinReusableIdentifier =
    [MyAnnotation
     reusableIdentifierforPinColor:senderAnnotation.pinColor];


    MKAnnotationView *annotationView = (MKAnnotationView *)
    [mapView
     dequeueReusableAnnotationViewWithIdentifier:
     pinReusableIdentifier];

    if (annotationView == nil){
        annotationView =
        [[MKAnnotationView alloc]  initWithAnnotation:senderAnnotation
                                      reuseIdentifier:pinReusableIdentifier];

        annotationView.canShowCallout = YES;

    }

    UIImage *pinImage = [UIImage imageNamed:@"Bike.png"];
    if (pinImage != nil){
        annotationView.image = pinImage;
        annotationView.canShowCallout = YES;
    }

    result = annotationView;

    return result;
}
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
    static NSString *AnnotationViewID = @"annotationViewID";

    MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];

    if (annotationView == nil)
    {
        annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
    }

    annotationView.image = [UIImage imageNamed:@"Bike.png"];
    annotationView.annotation = annotation;

    return annotationView;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM