Iphone 将NSString分解为纬度和经度坐标,并重新将MapView居中

Iphone 将NSString分解为纬度和经度坐标,并重新将MapView居中,iphone,ios,objective-c,Iphone,Ios,Objective C,我有一个NSString,其值为: NSString *combined = "10014, 40.734, -74.0053"; 我想将这个包含逗号的字符串分解为三个NSString,分别称为bZip、bLat和bLon,因此值如下所示: bZip = 10014 bLat = 40.734 bLon = -74.0053 然后我想使用bLat和bLon坐标来更新地图视图上的中心位置。MapView从JSON提要中提取数据并绘制出标记,但我需要将地图重新聚焦在bLat和bLon值中保存

我有一个NSString,其值为:

NSString *combined = "10014, 40.734, -74.0053";
我想将这个包含逗号的字符串分解为三个NSString,分别称为bZip、bLat和bLon,因此值如下所示:

bZip = 10014 
bLat = 40.734 
bLon = -74.0053
然后我想使用bLat和bLon坐标来更新地图视图上的中心位置。MapView从JSON提要中提取数据并绘制出标记,但我需要将地图重新聚焦在bLat和bLon值中保存的坐标上

我假设我需要在该行之后进行此更改:

[self.mapView1 addAnnotations:newAnnotations];
有人知道如何帮助我做到这一点吗?谢谢大家!

NSData *data = [NSData dataWithContentsOfURL:url];

NSError *error;
NSArray *array = [NSJSONSerialization JSONObjectWithData:data
                                                 options:0
                                                   error:&error];

CLLocationCoordinate2D location;                        
NSMutableArray *newAnnotations = [NSMutableArray array]; 
MapViewAnnotation *newAnnotation;                        

for (NSDictionary *dictionary in array)
{   
    location.latitude = [dictionary[@"placeLatitude"] doubleValue];
    location.longitude = [dictionary[@"placeLongitude"] doubleValue];

    newAnnotation = [[MapViewAnnotation alloc] initWithTitle:dictionary[@"name"]
                                               andCoordinate:location];

    [newAnnotations addObject:newAnnotation];


}

[self.mapView1 addAnnotations:newAnnotations];

示例代码:

NSArray *stringArray = [combined componentsSeparatedByString: @","];

NSString *bZip = [stringArray objectAtIndex:0];
NSString *bLat = [stringArray objectAtIndex:1];
NSString *bLon = [stringArray objectAtIndex:2];
试着用这个

    NSString *combined = "10014, 40.734, -74.0053";
    NSArray *data = [combined componentsSeparatedByString:@", "];

NSLog(@"bZip = %@",[data objectAtIndex:0]);
NSLog(@"bLat = %@",[data objectAtIndex:1]);
NSLog(@"bLon = %@",[data objectAtIndex:2]);

1.这与Xcode无关。2.你用谷歌搜索过这个吗?在堆栈溢出和其他地方也有大量的重复。3.如果没有,你至少试过自己做点什么吗?这是微不足道的,我可以列举3或4种方法来完成这一点。可能重复和@H2CO3,感谢您让我知道不要在iOS开发问题的标签中包含Xcode。在回答问题2时-是的,我已经在谷歌上搜索过了。这对我来说还不算微不足道,但我希望有一天能想出3到4种方法来做到这一点。非常感谢:)@H2CO3,建议关闭这个?或者我应该让其他人从中学习。我不想弄得乱七八糟,所以。。。谢谢你的指导。既然已经有四个副本了,我建议你删除它。在我看来,我们不需要更多的这个问题。(你也会找回你失去的14点声誉。)
 NSString *combined = @"10014, 40.734, -74.0053";
 NSArray *array = [combined componentsSeparatedByString:@","];