CllocationCoordinate2d к Cllocation
-
22-09-2019 - |
Вопрос
У меня есть следующий цикл в моем просмотре: загрузка:
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{
}
Пожалуйста, помогите мне, я застрял!
Спасибо всем за помощь заранее
Решение
CLLocation
имеет метод init -(id)initWithLatitude:(CLLocationDegrees)latitude longitude:(CLLocationDegrees)longitude
Анкет Затем используйте - (CLLocationDistance)getDistanceFrom:(const CLLocation *)location
Чтобы получить расстояние между двумя объектами Cllocation.
Другие советы
Простой
CLLocation *location = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
Для быщей толпы,
У меня есть метод, который называется «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)
}
«Как я могу использовать свой экземпляр в качестве Cllocation?»
Вы не можете, потому что это не один. Тебе следует Создай.
Не забудьте выпустить то, что вы выделяете. Видеть Правила управления памятью.
Если координат CCLocationCoordinate2D
, тогда вы можете назначить новичку из
**- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation**
делегировать, получив оба latitude
а также longitude
свойства координатного свойства CLLocation
Как ниже:
coord.latitude = newLocation.coordinate.latitude;
coord.longitude = newLocation.coordinate.longitude;