iOS Features – Displaying Zones on a map

A common requirement of geo-location apps is to present areas of interest to users on a map.

Point SDK for iOS provides methods making it easy to display your fences and beacons on a standard MapKit View. Fences can be shown as a colored shape, according to their appearance in Point Access. Beacons can be shown as an icon with a colored, radial gradient indicating their approximate maximum range.

Displaying map features

Getting started

The simplest way to display these features on an existing MKMapView is:

1. Add MKOverlays for Fences and Beacons to the map view, by using the following category method provided in MKMapView+BDPointSDK.h:

- (void)addOverlaysForZones: (NSSet *)zoneInfos withBeaconIconImage: (UIImage *)beaconIconImage beaconIconScale:(CGFloat)beaconIconScale

The zoneInfos parameter must contain only BDZoneInfo elements. Typically this will be the same zoneInfos collection received by the application’s didUpdateZoneInfo: callback in its BDPLocationDelegate implementation.

The beaconIconImage parameter is provided by your application to represent a Beacon and may be additionally scaled with the beaconIconScale parameter.

2. Adopt the following pattern in the mapView:rendererForOverlay: method of your MKMapView’s existing MKMapViewDelegate delegate (create and assign this delegate if one does not exist):

- (MKOverlayRenderer *)mapView: (MKMapView *)mapView rendererForOverlay: (id)overlay
{
    BDPointOverlayRendererFactory *rendererFactory = BDPointOverlayRendererFactory.sharedInstance;
 
    // You should also declare and initialize an NSCache as an instance variable named _overlayRendererCache, used below.
    MKOverlayRenderer *renderer = [ _overlayRendererCache objectForKey: overlay ];
 
    // A renderer does not already exist for this overlay, one must be created
    if( renderer == nil )
    {
        // Was this an overlay added by Point SDK?
        if( [ rendererFactory isPointOverlay: overlay ] )
        {
            // Yes, request a renderer from Point SDK's factory
            renderer = [ rendererFactory rendererForOverlay: overlay ];
        }
        else
        {
            // This overlay was not provided by Point SDK, provide your own custom renderer
            // TODO: Provide renderers for custom overlays
        }
 
        // Cache the newly created renderer
        [ _overlayRendererCache setObject: renderer forKey: overlay ];
    }
 
    return renderer;
}

Next steps

  • If you need to be more selective about which of your Zones features are displayed, or your app uses either Fences or Beacons exclusively, you can substitute use of the addOverlaysForZones:... method shown in step 1 above, with one of the other addOverlays... methods provided by MKMapView+BDPointSDK.h.
  • To draw your users attention to particular features, or groups of features, use any of Point SDK’s mapRectFor... methods. These return an MKMapRect which can be used in conjunction with MKMapViews existing setVisibleMapRect:... methods to scroll and zoom the map view to a relevant area.
  • You can continue to add other MKOverlays to the mapView for your non-Point SDK objects. Simply use theisPointOverlay: method as shown in step 2 of our example, to determine whether a given MKOverlay should be rendered by the Point SDK renderer or one of your own, at display time.
  • Our MKMapView category and the renderer factory class detailed here are provided to assist your development; if you wish to implement your own overlays and renderers for Point SDK’s spatial objects, BDFenceInfo and BDBeaconInfo, we encourage you to do so.
Created by Bluedot DevOps on June 19, 2018

Start the discussion