0

如果有人能在最后一段帮助我,我觉得我已经接近了!

目前我有以下内容:

{
   CLLocationCoordinate2D location;
   location.latitude = (double) 44.4758;
   location.longitude = (double) -73.2125;

   str = [[NSNumber numberWithDouble:location.longitude] stringValue];

   viewController.stringToDisplay = str;
}

现在,这是通过经度值,但它当然不会让我包括纬度。我可以写什么以将两者包含在同一行中?

谢谢!

4

2 回答 2

0

例如:

 str = [NSString stringWithFormat:@"%f, %f", location.latitude, location.longitude];

或更易于阅读:

 str = [NSString stringWithFormat:@"%.2f, %.2f", location.latitude, location.longitude];
于 2012-10-15T16:56:27.787 回答
0

做到了!!很高兴。我根据按下的按钮从前一个视图传递不同的坐标,并使用 IF 语句将这些坐标固定在下一个视图上。对于编程大师来说,这无疑是一件简单的事情,但我没有经验,所以我很高兴:)

-(void)viewWillAppear:(BOOL)animated

{
  CLLocationCoordinate2D location;
  NSLog(@"self.stringToDisplay = %@", self.stringToDisplay);

  if ([self.stringToDisplay isEqualToString: @"44.48, -73.21"])
  {
    location.latitude = (double) 44.4758;
    location.longitude = (double) -73.2125;

    MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"Burlington, VT" andCoordinate:location];
    [self.mapView addAnnotation:newAnnotation];
  }

  if ([self.stringToDisplay isEqualToString: @"51.50, -0.14"])
  {
    location.latitude = (double) 51.5010;
    location.longitude = (double) -0.1425;

    MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"Buckingham Palace" andCoordinate:location];
    [self.mapView addAnnotation:newAnnotation];
  }
}
于 2012-10-16T03:24:12.097 回答