首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >CLLocationCoordinate2D到CLLocation

CLLocationCoordinate2D到CLLocation
EN

Stack Overflow用户
提问于 2010-02-23 21:49:16
回答 4查看 39.9K关注 0票数 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];


  }

coord为CLLocationCoordinate2D

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

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

}

请帮帮我,我被困住了!

感谢你们事前的帮助

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2010-02-23 22:42:34

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

票数 42
EN

Stack Overflow用户

发布于 2014-07-19 04:49:23

简单

CLLocation *location = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
票数 14
EN

Stack Overflow用户

发布于 2014-11-12 02:19:17

对于斯威夫特的观众,

我有一个名为"fetchCafesArroundLocation“的方法,它会在地图移动后刷新。这就是我如何将经度和经度从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)

}
票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2318547

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档