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]; |
CREATING IMAGES ON THE MAP
To present an image on the map at specified coordinates, instantiate a dedicated object, NMGeoImage, with either initWithCoordinates:imagePath:imageScale: instance method or geoImageWithCoordinates:imagePath:imageScale: class method with a coordinates array representing an image's location on map, specified clockwise starting from the top left vertex and then add it to the map using NMMapView instance's addGeoObject: method:
Code Block | ||||
---|---|---|---|---|
| ||||
NMGeoImage *geoImage = [[NMGeoImage alloc] initWithCoordinates:coords imagePath:imagePath imageScale:imageScale]; /* or, alternatively*/ NMGeoImage *geoImage = [NMGeoImage geoImageWithCoordinates:coords imagePath:imagePath imageScale:imageScale]; */ [mapView addGeoObject:geoImage]; |
Alternatively an NMGeoImage can instantiated with independent corner coordinates initWithCoordinatesTopLeft:topRight:bottomLeft:bottomRight:imagePath:imageScale: instance method or geoImageWithCoordinatesTopLeft:topRight:bottomLeft:bottomRight:imagePath:imageScale: class method. After on object is being instantiated it can be added to the map using NMMapView instance's addGeoObject: method:
Code Block | ||||
---|---|---|---|---|
| ||||
NMGeoImage *geoImage = [[NMGeoImage alloc] initWithTopLeft:topLeft topRight:topRight bottomLeft:bottomLeft bottomRight:bottomRight imagePath:imagePath imageScale:imageScale]; /* or, alternatively*/ NMGeoImage *geoImage = [NMGeoImage geoImageWithCoordinatesTopLeft:topLeft topRight:topRight bottomLeft:bottomLeft bottomRight:bottomRight imagePath:imagePath imageScale:imageScale]; */ [mapView addGeoObject:geoImage]; |
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]; |
DRAWING CIRCLES
To draw a circle on the map use either initWithCenter:radius:strokeWidth:fillColor:strokeColor: instance method or geoCircleWithCenter:radius:strokeWidth:fillColor:strokeColor: class method. Pass an center of NMMapCoordinates representing circle's center geo position as the argument, a radius, a stroke width and color and a fill color. Add the circle instantiated with one of methods to the NMMapView instance:
Code Block | ||||
---|---|---|---|---|
| ||||
NMGeoCirce *circle = [[NMGeoCircle alloc] initWithCenter:center radius:radius strokeWidth:strokeWidth fillColor:fillColor strokeColor:strokeColor]; /* or, alternatively NMGeoCirce *circle = [NMGeoCirce geoCircleWithCenter:center radius:radius strokeWidth:strokeWidth fillColor:fillColor strokeColor:strokeColor]; */ [mapView addGeoObject:circle]; |
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 an 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]; |
INTERACTING WITH GEO OBJECTS
There three types of user events related to NMGeoObjects recognized by the SDK:
- single tap on a geo object
- double tap on a geo object
- long press on a geo object
To be able to handle these events make one of your classes conforming to NMGeoObjectListener protocol and add an instance of this class to the map view's geo object listeners. Methods onGeoObjectClick:, onGeoObjectDoubleClick: and onGeoObjectLongPress: will be called on these events:
Code Block | ||||
---|---|---|---|---|
| ||||
- (void)onGeoObjectClick:(NSUInteger)geoObjectID { //handle single tap on geo object here } - (void)onGeoObjectLongPress:(NSUInteger)geoObjectID { //handle long press on geo object here } |