How to plot the markers in google maps from a dictionay in ios?

前端 未结 2 1496
鱼传尺愫
鱼传尺愫 2020-12-22 13:17

In my app, I have done JSON parsing and I got the coordinates in the form of a dictionary, I want to use the coordinates angd plot it in the map,
I have using this

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-22 14:06

    try this one this might be helpful just create a for loop to your count ,increment it ...

    NSDictionary *dict=(NSDictionary *)[jsonData objectAtIndex:i];
        double la=[[dict valueForKey:@"latitude"] doubleValue];
        double lo=[[dict valueForKey:@"longitude"] doubleValue];
    
        NSMutableArray * latArray=[[NSMutableArray alloc]init];
        NSMutableArray * longArray=[[NSMutableArray alloc]init];
    
        [latArray addObject:[NSNumber numberWithDouble:la]];
        [longArray addObject:[NSNumber numberWithDouble:lo]];
    
        CLLocation * loca=[[CLLocation alloc]initWithLatitude:[[latArray objectAtIndex:i]doubleValue] longitude:[[longArray objectAtIndex:i]doubleValue]];
        CLLocationCoordinate2D coordi=loca.coordinate;
    
        GMSMarker *marker= [[GMSMarker alloc] init];
        marker=[GMSMarker markerWithPosition:coordi];
        marker.position = CLLocationCoordinate2DMake([[latArray objectAtIndex:i]doubleValue], [[longArray objectAtIndex:i]doubleValue]);
        marker.snippet = @"Hello World";
        marker.animated = YES;
        marker.map = mapView;
    

提交回复
热议问题