Saturday 15 August 2015

objective c - MKMapPointForCoordinate returning invalid coordinates -


I am working with MKMapView, annotations, overlays, etc., but I have a pain in the butt points (with MKMapPointForCoordinate Is coming back) is returning an invalid coordination.

Code:

  MKMapPoint * pointArr; (Category * route in valid routes) {NSString * routeID = [route route]; NSArray * pointData = [Object for route: route ID]; PointArr = malloc (size (Mkmappoint) * [dotdata count]); Int i = 0; (NSDRIVATION * ROUNDADA IN PYDENDATA) {NSSTING * LATITUS = [RADIADA ObjectForcae: @ "Latitude"]; NSSTING * longitude = [MARADA data objective: @ "longitude"]; NSLog (@ "L:% @ L:% @", latitude, longitude); CLLocationCoordinate2D coord = CLLocationCoordinate2DMake ([[number numberFromString: latitude] doubleValue], [[numberFromString: longitude] doubleValue]); NSLog (@ "Coord:% f% f", coord.latitude, coord.longitude); MKMapPoint Point = MKMapPointForCoordinate (Coordinate); NSLog (@ "point:% F% F", point.x, point.i); Point ARR [I] = dot; I ++; } M.K.Palline * Polyline = [MK Polyline PolylineWith Points: PointAR Count: i]; Polyline.title = [route name]; [Margaraway set object: Polyline fork: [route route]]; [Map addOverlay: Polyline]; Free pointArr; }   

Output example:

L: 41.380840 L: -83.6,41,31 9

Coord: 41.380840-83.6, 41,31 9

Point: 71850240.204982 100266073.824832

I do not understand why conversion to an MKMapPoint is destroying values ​​of my CLLocationCoordinate2D. The overlay is not visible on the map because the value is invalid ...

EDIT: I got the meaning of working using MKMapPointMake instead, but my overlay is still not showing up. This MapView is: ViewForOverlay: Code:

  - (MKOverlayView *) MapView: (MKMapView *) MapView viewForOverlay: (ID of & lt; MKOverlay & gt;) Overlay {MKOverlayView * overlayView = nil ; // Check if the overlay type is MKPolyline if ([overlay isKindOfClass: [MKPolyline class]]) {MKPolylineView * routeLineView = [[MKPolylineView alloc] initWithPolyline: overlay]; RouteLineView.strokeColor = [UIColor orange color]; RouteLineView.lineWidth = 10; View return overlay; } Return zero; }   

The method is called (a breakpoint is used to confirm), and I have annotations work (so the representative has to set up correctly, Feel)

Double edit: Facepam: I was not returning zero in the representative code every time. PP / P /

is a MKMapPoint no Degree in latitude / longitude (e.g. CLLocationCoordinate2D ).

They are not interchangeable and therefore you should not expect MKMapPoint x, y values ​​so that any explicit relation of related latitude and longitude can be shown.

A MKMapPoint is using X or Y values ​​on a flat launch of latitude and longitude, which are not in the same scale or range as latitude and longitude. For more detailed explanation please see the section in the Location Awareness Programming Guide.

By the way, if you have the CLLocationCoordinate2D value, it is very easy to create a polyline using the code> instead of polylinewith synchronized instead of polylinewithpoints . In this way, you do not need to bother with any conversions.

See for more details and examples.

No comments:

Post a Comment