Reputation: 111
I'm new to iPhone development, in my application I want to draw route between two points and show the multiple markers on my route. Now I'm done with the Route between two points but I don't know how to draw multiple markers on my route. So please help me to do this.
Thanks in Advance!!!
_markerStart = [GMSMarker new];
_markerStart.title = [[[routeDict objectForKey:@"legs"] objectAtIndex:0]objectForKey:@"start_address"];
_markerStart.icon = newImage; //[UIImage imageNamed:@"startMarker.png"];
_markerStart.map = gmsMapView;
_markerStart.position = startPoint;
_markerFinish = [GMSMarker new];
_markerFinish.title = [[[routeDict objectForKey:@"legs"] objectAtIndex:0]objectForKey:@"end_address"];
_markerFinish.icon = newImage; //[UIImage imageNamed:@"finishMarker.png"];
_markerFinish.map = gmsMapView;
_markerFinish.position = endPoint;
Here I have added start and end marker.
Upvotes: 2
Views: 1119
Reputation: 595
As you are completed with drawing route between two points, you will have co-ordinates for route. You can take some co-ordinates from those and draw them on Google Maps.
For drawing route you may have used GMSPolyline
. For polyline, you must have used GMSPath
. From path you can get co-ordinates by using method
-(CLLocationCoordinate2D)coordinateAtIndex:(NSUInteger)index
You can use these co-ordinates to plot the marker on route. GMSMarkers Doc
Check this code (here gmsPath as GMSPath
) EDIT:
//GMSPath *gmsPath;
//NSString *title;
for (int i = 0; i < [gmsPath count]; i++) {
CLLocationCoordinate2D location = [gmsPath coordinateAtIndex: i];
GMSMarker *marker = [GMSMarker markerWithPosition:location];
marker.title = title;
marker.icon = [UIImage imageNamed:@"marker_img.png"];
marker.map = self.mapView;
}
This will plot marker for each co-ordinate.
Upvotes: 1