CLLocationCoordinate2D в CLLocation
У меня есть следующий цикл в моем представленииDidLoad:
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
но как я могу использовать координацию в следующем методе, потому что мне нужно это, чтобы получить расстояние между двумя коордами:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation{
}
Пожалуйста, помогите мне, я застрял!
Благодарим вас за помощь заблаговременно
Ответы
Ответ 1
CLLocation
имеет метод init с именем -(id)initWithLatitude:(CLLocationDegrees)latitude longitude:(CLLocationDegrees)longitude
.
Затем используйте - (CLLocationDistance)getDistanceFrom:(const CLLocation *)location
, чтобы получить расстояние между двумя объектами CLLocation.
Ответ 2
Простой
CLLocation *location = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
Ответ 3
Для толпы Swift,
У меня есть метод под названием "fetchCafesArroundLocation", который обновляется после перемещения карты. Так я обработал получение Lat и Lon в CLLocation из CLLocationCoordiate2d, а затем передал переменную 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)
}
Ответ 4
"как я могу использовать свой экземпляр как CLLocation?"
Вы не можете, потому что это не одно. Вам нужно создать один.
Не забудьте освободить то, что вы выделите. См. правила управления памятью.
Ответ 5
Если координата является 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;