Jo Heyho Leute,
ich bins mal wieder - eure Nervensäge
Ich hab da mal 2 Fragen (sind eher Mathematischernatur xD)
Ich bastel ja gern mit dem MapKit rum (....) - jedenfalls würde ich gern zwei weitere Funktionen einbauen bzw. verbessern.
Normalerweise habe ich bereits eine "CenterMap" Funktion für 2 Koordinatenpunkte. (Meine Position und Ziel)
Diese sah erst so aus:
Alles anzeigen
Danach hab ich das ganz geändert in folgendes:
_routeRect ergab sich in dieser Funktion:
Alles anzeigen
Da ich nun aber das View Rotieren lasse (immer in Fahrtrichtung) fand ich es doof wenn es die größe von 320x460 behielt. Darum hab ich es einfach auf 600x600 vergrößert.
Nun passt das mit dem setVisibleRect natürlich nicht mehr...
Hat einer da von euch evtl. nen Tipp für mich ;D?
Achja mein zweites Problem!!!
Also wenn der Benutzer es will - agiert das App auch im Hintergrund - sprich es aktualisiert die Koordinaten des Ziels. Jedenfalls würde ich gern ein Funktion ausführen, falls die Ziel Koordinaten sich um 50, 100 oder 200 Meter entfernen von den ursprünglichen Koordinaten des Ziels.
Ergo ich hab kein Plan wie ich am besten die Distanz zweier Koordinaten Berechne (mitsicherheit gibt es da was vorgefertigtes xD)
Euer Nax
ich bins mal wieder - eure Nervensäge
Ich hab da mal 2 Fragen (sind eher Mathematischernatur xD)
Ich bastel ja gern mit dem MapKit rum (....) - jedenfalls würde ich gern zwei weitere Funktionen einbauen bzw. verbessern.
Normalerweise habe ich bereits eine "CenterMap" Funktion für 2 Koordinatenpunkte. (Meine Position und Ziel)
Diese sah erst so aus:
Quellcode
- MKCoordinateRegion region;
- CLLocationDegrees maxLat = -90;
- CLLocationDegrees maxLon = -150;
- CLLocationDegrees minLat = 90;
- CLLocationDegrees minLon = 150;
- for(int idx = 0; idx < routes.count; idx++)
- {
- CLLocation* currentLocation = [routes objectAtIndex:idx];
- if(currentLocation.coordinate.latitude > maxLat)
- maxLat = currentLocation.coordinate.latitude;
- if(currentLocation.coordinate.latitude < minLat)
- minLat = currentLocation.coordinate.latitude;
- if(currentLocation.coordinate.longitude > maxLon)
- maxLon = currentLocation.coordinate.longitude;
- if(currentLocation.coordinate.longitude < minLon)
- minLon = currentLocation.coordinate.longitude;
- }
- region.center.latitude = (maxLat + minLat) / 2;
- region.center.longitude = (maxLon + minLon) / 2;
- region.span.latitudeDelta = maxLat - minLat;
- region.span.longitudeDelta = maxLon - minLon;
- [mvKarte setRegion:region animated:YES];
Danach hab ich das ganz geändert in folgendes:
_routeRect ergab sich in dieser Funktion:
Quellcode
- - (void)loadRoute:(NSArray*)route {
- // while we create the route points, we will also be calculating the bounding box of our route
- // so we can easily zoom in on it.
- MKMapPoint northEastPoint;
- MKMapPoint southWestPoint;
- // create a c array of points.
- MKMapPoint* pointArr = malloc(sizeof(CLLocationCoordinate2D) * route.count);
- for(int idx = 0; idx < route.count; idx++)
- {
- // break the string down even further to latitude and longitude fields.
- NSString* currentPointString = [route objectAtIndex:idx];
- NSArray* latLonArr = [currentPointString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]];
- CLLocationDegrees latitude = [[latLonArr objectAtIndex:0] doubleValue];
- CLLocationDegrees longitude = [[latLonArr objectAtIndex:1] doubleValue];
- // create our coordinate and add it to the correct spot in the array
- CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);
- MKMapPoint point = MKMapPointForCoordinate(coordinate);
- //
- // adjust the bounding box
- //
- // if it is the first point, just use them, since we have nothing to compare to yet.
- if (idx == 0) {
- northEastPoint = point;
- southWestPoint = point;
- }
- else
- {
- if (point.x > northEastPoint.x)
- northEastPoint.x = point.x;
- if(point.y > northEastPoint.y)
- northEastPoint.y = point.y;
- if (point.x < southWestPoint.x)
- southWestPoint.x = point.x;
- if (point.y < southWestPoint.y)
- southWestPoint.y = point.y;
- }
- pointArr[idx] = point;
- }
- // create the polyline based on the array of points.
- self.routeLine = [MKPolyline polylineWithPoints:pointArr count:route.count];
- _routeRect = MKMapRectMake(southWestPoint.x, southWestPoint.y, northEastPoint.x - southWestPoint.x, northEastPoint.y - southWestPoint.y;
- // clear the memory allocated earlier for the points
- free(pointArr);
- }
Da ich nun aber das View Rotieren lasse (immer in Fahrtrichtung) fand ich es doof wenn es die größe von 320x460 behielt. Darum hab ich es einfach auf 600x600 vergrößert.
Nun passt das mit dem setVisibleRect natürlich nicht mehr...
Hat einer da von euch evtl. nen Tipp für mich ;D?
Achja mein zweites Problem!!!
Also wenn der Benutzer es will - agiert das App auch im Hintergrund - sprich es aktualisiert die Koordinaten des Ziels. Jedenfalls würde ich gern ein Funktion ausführen, falls die Ziel Koordinaten sich um 50, 100 oder 200 Meter entfernen von den ursprünglichen Koordinaten des Ziels.
Ergo ich hab kein Plan wie ich am besten die Distanz zweier Koordinaten Berechne (mitsicherheit gibt es da was vorgefertigtes xD)
Euer Nax
Meine Beiträge stehen unter der Beerware Lizenz!