我在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,因为我需要这个以获得两个坐标之间的距离:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation{
}
请帮助我,我被困了!
感谢大家提前帮助
答案 0 :(得分:40)
CLLocation
有一个名为-(id)initWithLatitude:(CLLocationDegrees)latitude longitude:(CLLocationDegrees)longitude
的init方法。
然后使用- (CLLocationDistance)getDistanceFrom:(const CLLocation *)location
获取两个CLLocation对象之间的距离。
答案 1 :(得分:11)
简单
CLLocation *location = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
答案 2 :(得分:8)
对于斯威夫特人群,
我有一个名为“fetchCafesArroundLocation”的方法,在地图移动后刷新。这就是我如何处理从CLLocationCoordiate2d将Lat和Lon引入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)
}
答案 3 :(得分:2)
答案 4 :(得分:0)
如果coord是CCLocationCoordinate2D
,那么您可以从中分配newLocation
**- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation**
通过获取latitude
坐标属性的longitude
和CLLocation
属性进行委托,如下所示:
coord.latitude = newLocation.coordinate.latitude;
coord.longitude = newLocation.coordinate.longitude;