Navmii SDK provides an easy way to present custom images on the map and to draw polylines. Children classes of NMGeoObject abstract class represent these custom images (NMGeoMarker) and polylines (NMGeoPolyline) in the SDK. NMMapView instance is responsible for creating and handling this type of objects.
CREATING MARKERS ON THE MAP
To present a marker on the map at specified coordinates with default image, instantiate it first with either initWithCoordinates: instance method or geoMarkerWithCoordinates: class method and, then, add it to the map using NMMapView instance's addGeoObject: method:
Code Block | ||||
---|---|---|---|---|
| ||||
NMGeoMarker *marker = [[NMGeoMarker alloc] initWithCoordinates:coords]; /* or, alternatively NMGeoMarker *marker = [NMGeoMarker geoMakerWithCoordinates:coords]; */ [mapView addGeoObject:marker]; |
To present a marker with specified image, use one of initWithCoordinates:andImagePath: and geoMarkerWithCoordinates:andImagePath: pair of methods. Make sure you add them to the map as in previous case:
Code Block | ||||
---|---|---|---|---|
| ||||
NMGeoMarker *marker = [[NMGeoMarker alloc] initWithCoordinates:coords andImagePath:pathToImage]; /* or, alternatively NMGeoMarker *marker = [NMGeoMarker geoMakerWithCoordinates:coords andImagePath:pathToImage]; */ [mapView addGeoObject:marker]; |
DRAWING POLYLINES
To draw a polyline on the map use either initWithVertices: instance method or geoPolylineWithVertices: class method. Pass an array of NMMapCoordinates representing polyline vertices geo position as the argument. Add the polyline instantiated with one of methods to the NMMapView instance:
Code Block | ||||
---|---|---|---|---|
| ||||
NMGeoPolyline *polyline = [[NMGeoPolyline alloc] initWithVertices:vertices]; /* or, alternatively NMGeoPolyline *polyline = [NMGeoPolyline geoPolylineWithVertices:vertices]; */ [mapView addGeoObject:polyline]; |
WORKING WITH POLYLINES
You can insert and remove a point or multiple points into and from a polyline, using NMGeoPolyline's appendVertex:, insertVertex:AtIndex:, removeLastVertex:, removeVertexAtIndex: and removeAllVertices methods. To retrieve overall vertices count use vertices property is a NSArray instance.
Code Block | ||||
---|---|---|---|---|
| ||||
//adds a vertex to the polyline's end [polyline appendVertex:coordinates]; //inserts a vertex into the polyline at index 3 if ([polyline.vertices count] >= 3) { [polyline insertVertex:coordinates atIndex:3]; } //removes last vertex from the polyline [polyline removeLastVertex]; //removes the vertex at index 3 from the polyline if ([polyline.vertices count] >= 3) { [polyline removeVertexAtIndex:3]; } //removes all vertices from the polyline [polyline removeAllVertices]; |
The way the polyline is rendered on the map is also customizable. You can change the polyline's color and width using NMGeoPolyline's color and width properties. The width property is CGFloat value representing polyline's width in Device-Independent Pixels (DIPs).
Code Block | ||||
---|---|---|---|---|
| ||||
//sets polyline width to 3 DPI
polyline.width = 3;
//sets polyline color to red
polyline.color = [UIColor colorWithRed:1.f green:0.f blue:0.f alpha:1.f];
|