बस MKPolyline का उपयोग: यह MapKit में मार्ग दिखाने के लिए संभव है
मैं googleMapsApi से पॉलीलाइन स्ट्रिंग मिलता है। मैं php के साथ सर्वर पर उसे पार्स और मेरे ऐप पर अंतिम polilyne स्ट्रिंग लौटाने।
NSMutableArray *points = [myApp decodePolyline:[route objectForKey:@"polyline"]];
if([points count] == 0)
{
return;
}
// 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) * [points count]);
for(int idx = 0; idx < points.count; idx++)
{
// break the string down even further to latitude and longitude fields.
NSString* currentPointString = [points 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);
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;
_currentLenght++;
}
// create the polyline based on the array of points.
self.routeLine = [MKPolyline polylineWithPoints:pointArr count:points.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);
if (nil != self.routeLine) {
[self.mapView addOverlay:self.routeLine];
}
[self.mapView setVisibleMapRect:_routeRect];
और दिखा रहा है:
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
MKOverlayView* overlayView = nil;
if(overlay == self.routeLine)
{
self.routeLineView = [[[MKPolylineView alloc] initWithPolyline:self.routeLine] autorelease];
self.routeLineView.fillColor = [UIColor blueColor];
self.routeLineView.strokeColor = TICNavigatorColor;
self.routeLineView.lineWidth = 7;
self.routeLineView.lineJoin = kCGLineJoinRound;
self.routeLineView.lineCap = kCGLineCapRound;
overlayView = self.routeLineView;
}
return overlayView;
}
कोशिश करो।