25

我的 viewDidLoad 中有以下循环:

    for(int i=1; i<[eventsArray count]; i++) {
  NSArray *componentsArray = [[eventsArray objectAtIndex:i] componentsSeparatedByString:@","];
  if([componentsArray count] >=6) {
   Koordinate *coord = [[Koordinate alloc] init];
   coord.latitude = [[componentsArray objectAtIndex:0] floatValue];
   coord.longtitude = [[componentsArray objectAtIndex:1] floatValue];
   coord.magnitude = [[componentsArray objectAtIndex:2] floatValue];
   coord.depth = [[componentsArray objectAtIndex:3] floatValue];
   coord.title = [componentsArray objectAtIndex:4];
   coord.strasse = [componentsArray objectAtIndex:5];
   coord.herkunft = [componentsArray objectAtIndex:6];
   coord.telefon = [componentsArray objectAtIndex:7];
   coord.internet = [componentsArray objectAtIndex:8];
   [eventPoints addObject:coord];


  }

坐标是 CLLocationCoordinate2D

但是我如何在以下方法中使用坐标,因为我需要这个来获得两个坐标之间的距离:

    - (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation{

}

请帮帮我,我被困了!

谢谢大家事先的帮助

4

5 回答 5

42

CLLocation有一个名为-(id)initWithLatitude:(CLLocationDegrees)latitude longitude:(CLLocationDegrees)longitude. 然后用于- (CLLocationDistance)getDistanceFrom:(const CLLocation *)location获取两个 CLLocation 对象之间的距离。

于 2010-02-23T14:42:34.153 回答
14

简单的

CLLocation *location = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
于 2014-07-18T20:49:22.643 回答
10

对于斯威夫特人群,

我有一个名为“fetchCafesArroundLocation”的方法,它会在地图移动后刷新。这就是我如何处理将 Lat 和 Lon 从 CLLocationCoordiate2d 获取到 CLLocation,然后将 CLLocation 变量传递给处理方法的方式。

func mapView(mapView: MKMapView!, regionDidChangeAnimated animated: Bool){

    var centre = mapView.centerCoordinate as CLLocationCoordinate2D

    var getLat: CLLocationDegrees = centre.latitude
    var getLon: CLLocationDegrees = centre.longitude


    var getMovedMapCenter: CLLocation =  CLLocation(latitude: getLat, longitude: getLon)

    self.lastLocation = getMovedMapCenter
    self.fetchCafesAroundLocation(getMovedMapCenter)

}
于 2014-11-11T18:19:16.630 回答
2

“如何将我的实例用作 CLLocation?”</p>

你不能,因为它不是一个。您需要创建一个.

不要忘记释放你分配的内容。请参阅内存管理规则

于 2010-02-24T16:05:50.990 回答
0

如果 coord 是 a CCLocationCoordinate2D,那么您可以从

**- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation**

通过获取以下坐标属性的latitude和属性进行委托:longitudeCLLocation

coord.latitude = newLocation.coordinate.latitude;
coord.longitude = newLocation.coordinate.longitude;
于 2012-02-16T04:41:14.760 回答