打图钉

来源:互联网 发布:大数据4v特征 编辑:程序博客网 时间:2024/04/29 23:06

- (void)viewDidLoad

{

   

      mapView=[MTMapViewmapViewWithFrame:CGRectMake(0, 0,self.view.bounds.size.width,self.view.bounds.size.height)Delegate:self];

 

 

    if(searchRouteRsp==nil){

        

        [UIHelp showHint:@"暂无商家" intView:self.view];

    }

    if(searchRouteRsp.dataArray!=nil){

        NSLog(@"%d",searchRouteRsp.dataArray.count);

//        MTAnnotationView *an2;

//        MTLabel *label2;

        for (int j=0; j<searchRouteRsp.dataArray.count; j++)

        {

            columnRespData=[searchRouteRsp.mColumnRespDataListobjectAtIndex:j];

            

        NSMutableArray *extendInfoArray=[searchRouteRsp.dataArrayobjectAtIndex:j];

            NSMutableArray *Level2=[extendInfoArrayobjectAtIndex:0];

            NSMutableDictionary *dataDictionary=[extendInfoArrayobjectAtIndex:1];

            

            NSLog(@"Level2--%d", Level2.count);

            

            MapExtendInfo *mlongitude=[Level2objectAtIndex:1];

            MapExtendInfo *mlatitude=[Level2objectAtIndex:2];

        

            NSLog(@"%@",mlongitude);

            UIImage *my=[UIImageimageNamed:@"pinRed.png"];

            CGRect imgFrame=CGRectMake(0, 0, my.size.width, my.size.height);


              MTAnnotationView *an2=[MTAnnotationViewannotationViewWithFrame:imgFrame UIImage:myDelegate:self];

//            MTLabel *mtLabel=[MTLabel  labelWithTitle:[NSString stringWithFormat:@"%@\r\n %@",columnRespData.mNode.nodename,[dataDictionary valueForKey:@"address"] ]Font:[UIFont fontWithName:@"STHeitik-Medium" size:18]];

            MTLabel *mtLabel=[MTLabel labelWithTitle:@" "Font:[UIFont fontWithName:@"STHeitik-Medium"size:15]];

             [mtLabel setFrame:CGRectMake(0, 0, 255, 105)];

            UILabel *shopContent=[[UILabelalloc]initWithFrame:CGRectMake(3, 0, 250, 100)];

            shopContent.backgroundColor=[UIColorclearColor];

            shopContent.lineBreakMode=UILineBreakModeCharacterWrap;

            shopContent.numberOfLines=0;

            shopContent.text=[NSStringstringWithFormat:@"%@\n地址:%@\n电话:%@",columnRespData.mNode.nodename, [dataDictionaryvalueForKey:@"address"],[dataDictionaryvalueForKey:@"telphone"]];

            shopContent.font=[UIFontfontWithName:@"STHeitik-Medium" size:15];

            shopContent.textColor=[UIColorwhiteColor];

           

            [mtLabel addSubview:shopContent];

//            [mtLabel setLabelPoint:CGPointMake(-50, 30)];

            

            [an2 addLabel:mtLabel];

            NSLog(@"%@",mlatitude.attrvalue);

             NSLog(@"%@",mlongitude.attrvalue);

            

            if(mlatitude.attrvalue!=0)

            {

            

            }

//            [an2 setUserInteractionEnabled:YES];

            if([mlatitude.attrvaluefloatValue]!=0&&[mlongitude.attrvaluefloatValue]!=0)

            {

            [an2 setCoordinate:CGPointMake( [mlongitude.attrvaluefloatValue],[mlatitude.attrvalue floatValue])];

               } 

            [an2 setHotXY:CGPointMake(7, 34.5)];

            [mapView addAnnotation:an2 ];

            

           

            

            if(j==0)

            {

                tempLatitude=[mlatitude.attrvaluefloatValue];

                tempLongitude=[mlongitude.attrvaluefloatValue];

               

            }


            

         

        }

        

    }


    CGPoint mapcenter=CGPointMake(tempLongitude,tempLatitude);

//    CGPoint mapcenter=CGPointMake(116.39716f, 39.91669f);

//     CGPoint mapcenter=CGPointMake(LATITUDE, LONGGITUDE);

    CGSize mapsize=CGSizeMake(0.04f,0.03f);

    CGRect region=CGRectMake(mapcenter.x, mapcenter.y, mapsize.width, mapsize.height);

    

    [mapView setRegion:regionanimated:NO];

    [mapView setCenterCoordinate:mapcenteranimated:NO];

    [self.viewaddSubview:mapView];

    [self.viewsendSubviewToBack:mapView];


    


     [superviewDidLoad];

}