SDK for iOS Developer's Guide

Maps

The core feature of SDK for iOS is Mapping. The key concepts covered in this section include adding a map to an iOS application, changing the location displayed by the map, and modifying its properties. The primary component of the mapping API is the NMAMapView, which is integrated with the Cocoa Touch framework as a UIView subclass. NMAMapView represents the view to display map and various properties. The NMAMapView is derived from UIView and is part of iOS Cocoa Touch framework.

Note: To create a simple map application, refer to Quick Start section.

The first step to integrate a map into an application is to insert a NMAMapView to your view controller .xib file or the storyboard of the application using the Interface Builder. Alternatively, you can also add NMAMapView to your view controller programmatically as follows:

- (void)viewDidLoad
{
  mapView = [[NMAMapView alloc] initWithFrame:self.view.frame];
  [self.view addSubview:mapView];
}

The NMAMapView class handles all user interactions in the form of touch gestures. More details about the supported gesture types can be found in Map Gestures section.

Working with NMAMapView

Once the NMAMapView is initialized, it can be manipulated and interacted in a variety of ways. Some key attributes of the NMAMapView are its geographical center (geoCenter) and zoom level (zoomLevel). These properties may be used to customize the NMAMapView display. For example, the following code demonstrates how to show a view of Vancouver, Canada.

NMAGeoCoordinates *geoCoordCenter = [[NMAGeoCoordinates alloc]
  initWithLatitude:49.260327 longitude:-123.115025];
[self.mapView setGeoCenter:geoCoordCenter withAnimation:NMAMapAnimationNone];
In the preceding code:
  • The geographical location [NMAGeoCoordinates] for the new map center is created by a call to -(id)initWithLatitude:(double)aLatitude longitude:(double)aLongitude method.
  • When setting the center of a map the transition can be animated by passing NMAMapAnimationLinear enum value to animation parameter. Animation can also be suppressed by using NMAMapAnimationNone value.

The beginning and ending of these events may be observed by assigning an object to NMAMapView delegate property. The object should implement the methods of NMAMapViewDelegate protocol corresponding to the events you wish it to receive. This delegate can also be used to detect map object selection.

Note: For optimum performance avoid resizing a map after it has been created. If resizing is necessary, create the map at the largest size to be used and reduce it later.

Resolution and Text Size

By default HERE SDK uses high-resolution (512 x 512 pixels) map tiles. You can set useHighResolutionMap property in NMAMapView to NO to use lower-resolution (256 x 256 pixels) map tiles instead.

You can also use mapPPI property to change the map pixel-per-inch setting. The default setting is NMAMapPPILow. Setting the property to NMAMapPPIHigh makes street labels and other texts to be bigger.

Properties of NMAMapView

The following examples show how to work with some of the properties in NMAMapView:

Map Center

The center of the map determines the geographical area to be displayed. It can be read using the NMAMapView geoCenter property and set using one of setGeoCenter: methods. Its type is NMAGeoCoordinates.

// Move the map to London
NMAGeoCoordinates *geoCoordCenter = [[NMAGeoCoordinates alloc]
initWithLatitude:51.51 longitude:-0.11];
[self.mapView setGeoCenter:geoCoordCenter withAnimation:NMAMapAnimationNone];

Zoom Level

The size of geographical area displayed on the map can be controlled by changing zoom level. The zoom level ranges from NMAMapViewMinimumZoomLevel to NMAMapViewMaximumZoomLevel, with a higher zoom value being closer to the ground. The following code sets the zoom level to the median zoom level:

// Set the zoom level to the median
mapView.zoomLevel =
(NMAMapViewMinimumZoomLevel + NMAMapViewMaximumZoomLevel)/2.0f;

Animations

The NMAMapView supports the following animation settings to be used while changing properties, defined by NMAMapAnimation enum:

  • NMAMapAnimationNone
  • NMAMapAnimationLinear
// Move to London using bow animation
NMAGeoCoordinates *geoCoordCenter = [[NMAGeoCoordinates alloc]
    initWithLatitude:51.51 longitude:-0.11];
[mapView setGeoCenter:geoCoordCenter withAnimation:NMAMapAnimationLinear];

Setting Multiple Attributes

An extended API is provided to change one or more attributes at the same time.

-(void) setGeoCenter:(NMAGeoCoordinates*) coordinates
           zoomLevel:(float) level
         withAnimation:(NMAMapAnimation) animation

To leave a map attribute unchanged, pass NMAMapViewPreserveValue constant to the relevant method parameter.

// Move to Vancouver preserving zoom level
NMAGeoCoordinates* coord = [[NMAGeoCoordinates alloc]
  initWithLatitude:49.0
  longitude:123.0];
[mapView setGeoCenter:coord
  zoomLevel:NMAMapViewPreserveValue
  withAnimation:NMAMapAnimationNone];

For more information about the APIs introduced and demonstrated in this section refer to the API Reference documentation.