如何在iPhone中的地图套件动态中获取pin弹出消息

发布于 2024-11-27 21:06:16 字数 1972 浏览 3 评论 0原文

我的任务是使用地图套件和 asp.net 的 Web 服务开发应用程序。

我的问题是当我从网络服务获取位置时。根据该位置,销钉也设置到其所在位置。

但我的问题是我已经在上面弹出了图钉。当用户单击图钉时,它会显示弹出窗口。但引脚上的弹出窗口不起作用。我已经包含了引脚和引脚弹出窗口的所有相关代码。但当我点击该引脚时它不起作用。

我还添加了代码以在地图上显示图钉和我给出的消息。

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
    NSLog(@"Controll comes here");

    if (annotation == mapView.userLocation) 
        return nil;

    MKPinAnnotationView *pin = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier: @"asdf"];

    if (pin == nil)
        pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier: @"asdf"] autorelease];

    else

    pin.annotation = annotation;
    pin.userInteractionEnabled = YES;
    UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    [disclosureButton setFrame:CGRectMake(0, 0, 30, 30)];

    pin.rightCalloutAccessoryView = disclosureButton;
    pin.pinColor = MKPinAnnotationColorRed;
    pin.animatesDrop = YES;
    [pin setEnabled:YES];
    [pin setCanShowCallout:YES];
    return pin;

}

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    NSString *strTitle = [NSString stringWithFormat:@"%@",[lines objectAtIndex:i]];
    NSMutableDictionary *d;
    NSMutableArray *temp=[NSArray arrayWithArray:lat];

    //  NSArray *temp=[NSArray arrayWithArray:[NSArray arrayWithArray:[reports objectAtIndex:0]]];
    for (int k = 0; k< i -1; k++)
    {
        d = (NSMutableDictionary*)[temp objectAtIndex:k];
        NSString *strAddress = [NSString stringWithFormat:@"%@",[d valueForKey:@"comments"]];

        if([strAddress isEqualToString:strTitle]) {
            [self presentModalViewController:self.nxtDetailsVCtr animated:YES];
            [self.nxtDetailsVCtr.lblDetail setText:strAddress];     
            break;
        }


    }
}

I have a task to develop the application with map kit and web service of asp.net.

My problem is when I got the location from the web service. And according that location the pin is also setting to it's located place.

But my problem is I have given the pin pop up on it. it is working when the user click on the pin it will show the pop up. but the pop up on the pin is not working. I have included all related code for the pin and pin pop up. but it is not working when I am clicking on that pin.

I am also adding the code to display the pin on map and message which I have given.

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
    NSLog(@"Controll comes here");

    if (annotation == mapView.userLocation) 
        return nil;

    MKPinAnnotationView *pin = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier: @"asdf"];

    if (pin == nil)
        pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier: @"asdf"] autorelease];

    else

    pin.annotation = annotation;
    pin.userInteractionEnabled = YES;
    UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    [disclosureButton setFrame:CGRectMake(0, 0, 30, 30)];

    pin.rightCalloutAccessoryView = disclosureButton;
    pin.pinColor = MKPinAnnotationColorRed;
    pin.animatesDrop = YES;
    [pin setEnabled:YES];
    [pin setCanShowCallout:YES];
    return pin;

}

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    NSString *strTitle = [NSString stringWithFormat:@"%@",[lines objectAtIndex:i]];
    NSMutableDictionary *d;
    NSMutableArray *temp=[NSArray arrayWithArray:lat];

    //  NSArray *temp=[NSArray arrayWithArray:[NSArray arrayWithArray:[reports objectAtIndex:0]]];
    for (int k = 0; k< i -1; k++)
    {
        d = (NSMutableDictionary*)[temp objectAtIndex:k];
        NSString *strAddress = [NSString stringWithFormat:@"%@",[d valueForKey:@"comments"]];

        if([strAddress isEqualToString:strTitle]) {
            [self presentModalViewController:self.nxtDetailsVCtr animated:YES];
            [self.nxtDetailsVCtr.lblDetail setText:strAddress];     
            break;
        }


    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

困倦 2024-12-04 21:06:16

为此,您需要为此实现以下代码

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    NSString *strTitle = [NSString stringWithFormat:@"%@",[view.annotation title]];
    NSMutableDictionary *d;
    NSArray *temp=[NSArray arrayWithArray:[NSArray arrayWithArray:[reports objectAtIndex:0]]];
    for (int i = 0; i<[temp count]; i++)
    {
        d = (NSMutableDictionary*)[temp objectAtIndex:i];
        NSString *strAddress = [NSString stringWithFormat:@"%@",[d valueForKey:@"comments"]];

            if([strAddress isEqualToString:strTitle])
            {
                if(!nxtDetails){
                   nxtDetails=[[MyCityDetails alloc] initWithNibName:@"MyCityDetails" bundle:nil];
                }
                NSLog(@"%@",[dForAnnotation valueForKey:@"report_types"]);
                nxtDetails.dForAnnotation= dForAnnotation;
nxtDetails.arForAnnotation=d;
                [self.navigationController pushViewController:nxtDetails animated:YES];
            }

    }
}

For that u need to implement the below code for that

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    NSString *strTitle = [NSString stringWithFormat:@"%@",[view.annotation title]];
    NSMutableDictionary *d;
    NSArray *temp=[NSArray arrayWithArray:[NSArray arrayWithArray:[reports objectAtIndex:0]]];
    for (int i = 0; i<[temp count]; i++)
    {
        d = (NSMutableDictionary*)[temp objectAtIndex:i];
        NSString *strAddress = [NSString stringWithFormat:@"%@",[d valueForKey:@"comments"]];

            if([strAddress isEqualToString:strTitle])
            {
                if(!nxtDetails){
                   nxtDetails=[[MyCityDetails alloc] initWithNibName:@"MyCityDetails" bundle:nil];
                }
                NSLog(@"%@",[dForAnnotation valueForKey:@"report_types"]);
                nxtDetails.dForAnnotation= dForAnnotation;
nxtDetails.arForAnnotation=d;
                [self.navigationController pushViewController:nxtDetails animated:YES];
            }

    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文