Drawing polyines or routes in Route-Me

398 views
Skip to first unread message

Noli Sicad

unread,
Feb 28, 2011, 1:28:48 AM2/28/11
to route-...@googlegroups.com
Hi,

How do we do Drawing polyines or routes in Route-Me?

These new classes and protocols in MK iiOS 4 are:
MKCircle
MKCircleView
MKMultiPoint
MKOverlayPathView
MKPolygon
MKPolygonView
MKPolyline
MKPolylineView
MKShape
MKOverlay

Drawing polyines or routes on a MKMapView in iOS4 – Part 3
http://spitzkoff.com/craig/?p=136

Any example to these things in Route-Me?

Thanks.

Noli

Andrew Johnson

unread,
Feb 28, 2011, 1:43:02 AM2/28/11
to route-...@googlegroups.com, Noli Sicad
Try this:

// where myCoordinate1 and myCoordinate2 are CLLocationCoordinate2D instances
RMPath *path = [[[RMPath alloc] initForMap:mapView] autorelease];
[path addLineToLatLong:myCoordinate1];
[path addLineToLatLong:myCoordinate2];
[path setLineWidth:3];
[path setFillColor:[UIColor redColor]];
[path setDrawingMode:kCGPathStroke];
[path setDrawing:YES];
[mapView.contents.overlay addSublayer:path];

Andrew

Andrew Johnson
Co-founder
www.GaiaGPS.com
415 335 7447

> --
> You received this message because you are subscribed to the Google Groups "route-me" group.
> To post to this group, send email to route-...@googlegroups.com.
> To unsubscribe from this group, send email to route-me-map...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/route-me-map?hl=en.
>

Noli Sicad

unread,
Feb 28, 2011, 2:33:11 AM2/28/11
to Andrew Johnson, route-...@googlegroups.com
Hi Andrew,

Thanks for the pointers,

However, it is very hard to understand this thing without an example
RMPath Example
Project.

I have searching the net for a sample RMPath project example even just
to plot a point in the MapView. So far no luck on this, just bit
pieces - break crumps.

I am getting near on my final objective in getting Spatialite Visual
Query to render polylines Route-Me or in MapKit.

Thanks.

Noli

Noli Sicad

unread,
Feb 28, 2011, 11:05:25 PM2/28/11
to route-...@googlegroups.com
Hi,


// Trying to convert this routine CVS to Layer for RMPath

// creates the route (MKPolyline) overlay
-(void) loadRoute
{
NSString* filePath = [[NSBundle mainBundle] pathForResource:@"route"
ofType:@"csv"];
NSString* fileContents = [NSString stringWithContentsOfFile:filePath
encoding:NSUTF8StringEncoding error:nil];
NSArray* pointStrings = [fileContents
componentsSeparatedByCharactersInSet:[NSCharacterSet
whitespaceAndNewlineCharacterSet]];


// 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.
RMProjectedPoint northEastPoint; // MKMapPoint is RMProjectedPoint
RMProjectedPoint southWestPoint;

// create a c array of points.
RMProjectedPoint* pointArr = malloc(sizeof(CLLocationCoordinate2D) *
pointStrings.count);

for(int idx = 0; idx < pointStrings.count; idx++)
{
// break the string down even further to latitude and longitude fields.
NSString* currentPointString = [pointStrings 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);


CLLocationCoordinate2D coordinate =
CLLocationCoordinate2DMake(latitude, longitude);

/~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Working up to here. The problems are in here below.
//


//MKMapPoint point = MKMapPointForCoordinate(coordinate);
RMProjectedPoint point = CLLocationCoordinate2D coordinate;

// MKMapPointForCoordinate is RMLatLong

//
// 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:pointStrings.count];
self.routeLine = [addLineToLatLong polylineWithPoints:pointArr
count:pointStrings.count];

// Guessing about this function CGRectMake

// _routeRect = MKMapRectMake(southWestPoint.x, southWestPoint.y,
northEastPoint.x - southWestPoint.x, northEastPoint.y -
southWestPoint.y);

_routeRect = CGRectMake(southWestPoint.x, southWestPoint.y,
northEastPoint.x - southWestPoint.x, northEastPoint.y -
southWestPoint.y);

// clear the memory allocated earlier for the points
free(pointArr);

}

Any ideas how to fix this.

Again, it is parsing CVS coordinates into layer. How do we do this in RMPath?

Thanks.

Noli

Reply all
Reply to author
Forward
0 new messages