Map View

The map is displayed on the screen via NMMapView which is a UIView subclass and is therefore integrated with Cocoa Touch framework. It can be interacted by the user's gestures right after NMSdk is initialized. You can refer to Map Gestures (v2.0.x) section to get more information on all possible user's gestures. 

CREATING THE MAP VIEW

To present the map on the screen, create an instance of NMMapView, add it to the view hierarchy and start the SDK with the following code:

#import <NavmiiSDK/NMNavmiiSDK.h>
// in implementation
- (void)viewDidLoad {
    [super viewDidLoad];
    mapView = [[NMMapView alloc] initWithFrame:frame];
    [self.view addSubview:mapView];
    [navmiiSDK setActiveMapView:mapView];
    [navmiiSDK startWithSettings:[NMConfigurationSettings settingsWithCustomResourcesPath:customResourcesPath
                                                                          offlineMapsPath:mapsPath
                                                                           innerFilesPath:innerFilesPath]];
}

Alternatively, you can create NMMapView in a .xib or a .storyboard file.

GPS COORDINATES - SCREEN POSITION TRANSFORMATION

You can transform CGPoint representing a screen position of a point on the map to NMMapCoordinates object representing corresponding GPS location using NMMapView's projection property, which is an instance of NMMapProjection class, and the following code:

NMMapCoordinates *coordinates = [mapView.projection mapCoordinatesFromScreenPosition:point];

The reverse operation can be performed by NMMapProjection's screenPositionFromMapCoordinates: method.

CGPoint point = [mapView.projection screenPositionFromMapCoordinates:coordinates];

To retrieve current GPS position relative to the screen use NMMapView's gpsPositionAnchorOnScreen readonly property.

CGPoint point = mapView.gpsPositionAnchorOScreen;

Note: south hemisphere latitudes are represented by negative values.

WORKING WITH CAMERA

Typically, you want to adjust the area presented on the map on your app's events. You can do it by using NMMapView's cameraController property (instance of NMCameraController class) which moves camera to a desired position. The camera position itself is represented in Navmii SDK as NMCameraPosition. NMCameraPosition and NMCameraController allow you to perform the following operations:

  • Setting map rotation via heading property
  • Setting map center via targetLocation property
  • Setting map zoom via zoom property
  • Setting map tilt via tilt property

This code instatiates a NMCameraPosition:

NMCameraPosition *targetPosition = [[NMCameraPosition initWithTargetLocation:location
                                                                     heading:heading 
                                                                        tilt:tilt
                                                                        zoom:zoom;

To move the camera to a position without animation use NMCameraController's moveCameraToPosition: method:

[mapView.cameraController moveCameraToPosition:position];


Alternatively, you can set the desired camera position with animation, using animateCameraToPosition:, animateCameraToPosition:completion:, animateCameraToPosition:duration:completion: methods. In first two cases the camera will be animated with the default duration of 0.5 second.

//sets the map camera's position with duration of 1.5 seconds
//and logs out the result when animation finishes or is canceled
[mapView.cameraController animateCameraToPosition:targetPosition
                                         duration:1.5
                                       completion:^(BOOL finished, BOOL canceled) {

                                          if (finished)
                	                      NSLog(@"animation finished");

                                          if (canceled)
                                          NSLog(@"animation canceled");
                                       };

To stop the animation currently in action use NMMapView's stopAnimation method:

[mapView stopAnimation];

HANDLING CAMERA EVENTS

These are the events on which the SDK informs you, if you have a class conforming to NMCameraMovementListener protocol and have added an instance of this class to NMCameraController object's listeners:

  • camera movement started
  • camera position changed changed
  • camera movement stopped
  • camera movement was cancelled
//adds ViewController to cameraController's listeners when Navmii Sdk starts
@interface ViewController () <NMCameraMovementListener>
@end
//in implementation (make sure your ViewController object responds to NMSdkStateChangeListener events)
- (void)onSdkStarted {
	[mapView.cameraController addCameraMovementListener:self];
}

These events have corresponding methods in NMCameraMovementListener protocol:

- (void)onCameraMovementStarted {
	//handle "movement started" event here
}
- (void)onCameraMovementIterated {
	//handle "camera position changed" event here
}
- (void)onCameraMovementStopped {
	//handle "camera movement stopped" event here
}
- (void)onCameraMovementCanceled {
	//handle "camera movement was canceled" event here
}

You also can add multiple listeners to a NMCameraController instance. To detach a listener use removeCameraMovementListener: method.