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

前端 未结 2 1481
鱼传尺愫
鱼传尺愫 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;
    
    0 讨论(0)
  • 2020-12-22 14:22

    I think , You have to alloc Marker in for loop, right now you are creating only one marker,

    for(int i=0;i<[jsonData count];i++)
    {
      NSDictionary *dict=(NSDictionary *)[jsonData objectAtIndex:i];
    double la=[dict valueForKey:@"latitude" doubleValue];
    double lo=[dict valueForKey:@"longitude" doubleValue];
    
    CLLocation * loca=[[CLLocation alloc]initWithLatitude:la longitude:lo];
    CLLocationCoordinate2D coordi=loca.coordinate;
    
     GMSMarker *marker= [[GMSMarker alloc] init];
    marker=[GMSMarker markerWithPosition:coordi];
        marker.snippet = @"Hello World";
        marker.animated = YES;
        marker.map = mapView;
    .....
    
    }
    
    0 讨论(0)
提交回复
热议问题