Skip to content

tagipedia/tmaps-ios-sample

Repository files navigation

tmaps-ios-sample

Installation

To integrate TMaps into your Xcode project, add it to your project:

  1. Create folder named tmapswww
  2. Download and Unzip map package inside tmapswww (Request map package from Tagipedia Team)
  3. Duplicate Config.Secrets.Example.plist and rename it to 'Config.Secrets.plist' and fill the file with your configration info
  4. Read our sample for examples

How it works

it works using dispatch actions between your APP and TMaps. So your APP dispatch actions to TMaps and TMaps dispatch actions to your APP.

Usage

TMaps actions dispatched to Your APP

dispatched when TMaps ready to receive dispatches from Your APP. So you should not dispatch any action before TMaps get ready.

@{
   @"type": @"READY"
};

dispatched when map loaded and visible to user.

@{
   @"type": @"MAP_LOADED"
};

Features tapped

dispatched when features in map tapped.

@{
   @"type": @"FEATURES_TAPPED",
   @"features": features
};

    features
    Required NSArray with NSDictionary, each NSDictionary with id, properties keys


Associated feature tapped

dispatched when features in map tapped with the top feature visible to user.

@{
   @"type": @"ASSOCIATED_FEATURE_TAPPED",
   @"feature_id": feature_id,
   @"feature": feature
};

    feature_id
    Required NSString with valid feature id

    feature
    Required NSDictionary with id, properties keys


Category marked

dispatched when select category in map

@{
   @"type": @"CATEGORY_MARKED",
   @"category": category
};

    category
    Required valid NSString category


Error

dispatched when error happened in TMaps

@{
   @"type": @"ERROR",
   @"error": error
};

    error
    Required NSDictionary with stack key and NSString value


Feature marked

dispatched after MARK_FEATURE ended

@{
   @"type": @"FEATURE_MARKED",
   @"feature_id": feature_id
};

    feature_id
    Required NSString with valid feature id


dispatched after HIGHLIGHT_FEATURE ended

@{
   @"type": @"FEATURE_HIGHLIGHTED",
   @"feature_id": feature_id
};

    feature_id
    Required NSString with valid feature id


dispatched after SET_ZOOM ended

@{
   @"type": @"ZOOM_ENDED"
};

dispatched after SET_CENTER ended

@{
   @"type": @"CENTER_ENDED"
};

dispatched after any event happened in TMaps. Your app can send analytics after receive this action.

@{
   @"type": @"EVENT_LOGGED",
   @"event_category": @"Maps",
   @"event_action": @"Loaded",
   @"event_label": map_name,
   @"fields_object": @{
    @"map_id": map_id
   }
};
@{
   @"type": @"EVENT_LOGGED",
   @"event_category": @"Features",
   @"event_action": @"Tapped",
   @"event_label": feature_display_name,
   @"fields_object": @{
    @"map_id": map_id,
    @"feature_id": feature_id
   }
};
@{
   @"type": @"EVENT_LOGGED",
   @"event_category": @"Features",
   @"event_action": @"Highlighted",
   @"event_label": feature_display_name,
   @"fields_object": @{
    @"map_id": map_id,
    @"feature_id": feature_id
   }
};
@{
   @"type": @"EVENT_LOGGED",
   @"event_category": @"Features",
   @"event_action": @"Searched",
   @"event_label": feature_display_name,
   @"fields_object": @{
    @"map_id": map_id,
    @"feature_id": feature_id
   }
};
@{
   @"type": @"EVENT_LOGGED",
   @"event_category": @"Categories",
   @"event_action": @"Highlighted",
   @"event_label": category,
   @"fields_object": @{
    @"map_id": map_id
   }
};
@{
   @"type": @"EVENT_LOGGED",
   @"event_category": @"Categories",
   @"event_action": @"Searched",
   @"event_label": category,
   @"fields_object": @{
    @"map_id": map_id
   }
};
@{
   @"type": @"EVENT_LOGGED",
   @"event_category": @"Routes",
   @"event_action": @"Routed",
   @"event_label": source_display_name => target_display_name,
   @"fields_object": @{
    @"map_id": map_id,
    @"source_feature_id": source_feature_id,
    @"target_feature_id": target_feature_id
   }
};
@{
   @"type": @"EVENT_LOGGED",
   @"event_category": @"Buildings",
   @"event_action": @"Tapped",
   @"event_label": building_name,
   @"fields_object": @{
    @"map_id": map_id,
    @"building_id": building_id
   }
};
@{
   @"type": @"EVENT_LOGGED",
   @"event_category": @"Buildings",
   @"event_action": @"Opened",
   @"event_label": building_name,
   @"fields_object": @{
    @"map_id": map_id,
    @"building_id": building_id
   }
};
@{
   @"type": @"EVENT_LOGGED",
   @"event_category": @"Floors",
   @"event_action": @"Opened",
   @"event_label": floor_label,
   @"fields_object": @{
    @"map_id": map_id,
    @"layer_id": layer_id
   }
};
@{
   @"type": @"EVENT_LOGGED",
   @"event_category": @"RenderModes",
   @"event_action": @"Changed",
   @"event_label": render_mode,
   @"fields_object": @{
    @"map_id": map_id
   }
};
@{
  @"type": @"EVENT_LOGGED",
  @"event_category": @"LocationUpdated",
  @"event_action": @"Gps",
  @"event_label": latitude/longitude,
  @"fields_object": @{
   @"map_id": map_id,
   @"lat": latitude,
   @"lng": longitude,
  }
};
@{
  @"type": @"EVENT_LOGGED",
  @"event_category": @"LocationUpdated",
  @"event_action": @"Beacon",
  @"event_label": latitude/longitude,
  @"fields_object": @{
   @"map_id": map_id,
   @"lat": latitude,
   @"lng": longitude,
  }
};

dispatched after Tapped GPS Button in TMaps. You Should turn on Location Service and then dispatch Start to begin updating location

@{
   @"type": @"CHECK_GPS_AVAILABILITY"
};

dispatched after Tapped Beacon Location Button in TMaps. You Should turn on Bluetooth Service and then dispatch Start to begin updating location

@{
   @"type": @"CHECK_BEACON_LOCATION_AVAILABILITY"
};

dispatched after starting updating beacon location in TMaps. You Should start or stop beacon manager according to beacon manager state. if beacon manager state is true you shoud start beacon manager then dispatch the new position to TMaps to update user location

@{
   @"type": @"START_POSITION_UPDATES_FOR_BEACON_LOCATION"
   @"start_beacon_manager":start_beacon_manager
};

    start_beacon_manager
    Required Boolean beacon manager state

dispatch it to set tenants of map.

@{
   @"type": @"SET_TENANT_DATA",
   @"payload": tenants_json
};

    payload
    Required NSArray with NSDictionary, each NSDictionary with id, feature_id, name, booth_id, icon, CUSTOM_KEYS_YOU_NEED keys


dispatch it to change default feature popup template.

@{
   @"type": @"SET_DEFAULT_FEATURE_POPUP_TEMPLATE",
   @"template": template,
   @"template_custom_data": templateCustomData,
};

    template
    Required valid NSString angular template with PopupScope

    template_custom_data
    Optional NSDictionary with CUSTOM_KEYS_YOU_NEED keys and NSString, NSNumber, NSArray, NSDictionary values
template custom data of keys that you want to use from customData in PopupScope


Set theme

dispatch it to change theme of map.

@{
   @"type": @"SET_THEME",
   @"theme": @{
      @"primary": primary_color,
      @"accent": accent_color
   }
};

    primary
    Optional valid NSString color

    accent
    Optional valid NSString color


Load map

dispatch it to load map.

@{
   @"type": @"LOAD_MAP",
   @"map_id": map_id,
   @"theme": @{
      @"primary": primary_color,
      @"accent": accent_color
   },
   @"center": @[lng, lat],
   @"zoom": zoom
};

    map_id
    Required NSString

    theme
    Optional NSDictionary with primary, accent keys and valid NSString color values theme used for colors such as buttons and loading

    center
    Optional NSArray of NSNumbers Default map center in longitude and latitude

    zoom
    Optional NSNumber Default zoom level


Change render mode

dispatch it to change render mode.

@{
   @"type": @"CHANGE_RENDER_MODE",
   @"modeToRender": modeToRender
}

    modeToRender     Required NSString with 2D, 3D


Set zoom

dispatch it to change zoom of map.

@{
   @"type": @"SET_ZOOM",
   @"zoom": zoom,
   @"zoom_type": zoom_type,
}

    zoom     Required NSNumber

    zoom_type     Optional NSString with FLY_TO


Set center

dispatch it to change center of map.

@{
   @"type": @"SET_CENTER",
   @"center": @[lng, lat],
}

    center     Required NSArray of NSNumbers Default map center in longitude and latitude


dispatch it to highlight feature.

@{
   @"type": @"HIGHLIGHT_FEATURE",
   @"feature_id": feature_id
}

    feature_id     Required NSString with valid feature id


Mark feature

dispatch it to mark feature.

@{
   @"type": @"MARK_FEATURE",
   @"feature_id": feature_id
}

    feature_id     Required NSString with valid feature id


Show GPS Button

dispatch it after Map Loaded to show GPS button

@{
   @"type": @"ENABLE_GPS_BUTTON"
}

dispatch it after check location service to start updating user location and showing nearest places to user

@{
   @"type": @"START_UPDATING_LOCATION",
   @"is_gps_activated": is_gps_activated
}

    is_gps_activated     Required Boolean

Don't forget to add permissions to Info.plist

<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>to show nearest area to you</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>to show nearest area to you</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>to show nearest area to you</string>

** Follow our samples **

[controller dispatch:@{@"type": @"ENABLE_GPS_BUTTON"}];

} else if ([type isEqualToString:@"CHECK_GPS_AVAILABILITY"]) {
if(![CLLocationManager locationServicesEnabled]){
[self checkLocationServicesAndStartUpdates:controller];
}
else {
[controller dispatch:@{@"type": @"START_UPDATING_LOCATION", @"is_gps_activated": @true }];
}
}

-(void) checkLocationServicesAndStartUpdates:(TGMapViewController *)controller {
tgController = controller;
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[locationManager requestWhenInUseAuthorization];
}
if (![CLLocationManager locationServicesEnabled] && [CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Need Location Services"
message:@"We would like to use your location. Please enable location services from Settings > Location Services"
delegate:self
cancelButtonTitle:@"Settings"
otherButtonTitles:@"Later", nil];
[alertView show];
}
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if(buttonIndex == 0)//Settings button pressed
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
}
}
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
if (![CLLocationManager locationServicesEnabled]) {
[tgController dispatch:@{@"type": @"START_UPDATING_LOCATION", @"is_gps_activated": @false }];
}
else {
[tgController dispatch:@{@"type": @"START_UPDATING_LOCATION", @"is_gps_activated": @true }];
}
}


Show Beacon Location Button

dispatch it after Map Loaded to show Beacon Location button

@{
   @"type": @"ENABLE_BEACON_LOCATION_BUTTON"
}

dispatch it after check beacon location service to start updating user location and showing nearest places to user

@{
   @"type": @"START_UPDATING_BEACON_LOCATION",
   @"is_beacon_location_activated": is_beacon_location_activated
}

    is_beacon_location_activated     Required Boolean


dispatch it after beacon location service started to update user location and showing nearest places to user

@{
   @"type": @"SET_USER_BEACON_LOCATION",
   @"x": x,
   @"y": y,
   @"origin_lat": origin_lat,
   @"origin_lng": origin_lng
}

    x     Required NSNumber
    y     Required NSNumber
    origin_lat     Required NSNumber
    origin_lng     Required NSNumber


dispatch it to set device id and device type

@{
   @"type": @"SET_DEVICE_DATA",
   @"device_id": device_id ,
   @"device_type": @"IOS"
}

    device_id     Required NSString

    device_type     Required NSString with IOS


dispatch it to set client id and client secret

@{
   @"type": @"SET_APPLICATION_SECRETS",
   @"client_id": client_id ,
   @"client_secret": client_secret
}

    client_id     Required NSString

    client_secret     Required NSString

Types

poi

current feature

poi

    poi     Required poi


enableRouting

Boolean to check if routing is enabled

enableRouting

showRoutingDialog

method to show routing dialog.

showRoutingDialog($event, data)

    $event     Required $event

    data     Optional Object with from, to keys and poi value


applyIfneeded

method to call Angular $apply

applyIfneeded(callback)

    callback     Required Function


custom data object that have all keys of template_custom_data

customData[key]

    key     Required with valid key from template_custom_data


dispatch

method to dispatch action from your APP to TMaps.

dispatch(action)

    action     Required Object with valid action


method to dispatch action from TMaps to your APP.

dispatchToContainer(action)

    action     Required Object with type, CUSTOM_KEYS_YOU_NEED keys.
type is NSString value.
CUSTOM_KEYS_YOU_NEED is any of NSString, NSNumber, NSArray, NSDictionary values.


closeInfo

method to close feature popup

closeInfo()

id

id of feature

poi.id

category

category of feature

poi.category

tags

tags of feature

poi.tags

getTenant

tenant of feature you set in SET_TENANT_DATA

poi.getTenant()

tenant name of feature you set in SET_TENANT_DATA

poi.getTenantName()

tenant icon of feature you set in SET_TENANT_DATA

poi.getTenantIcon()

tenant booth_id of feature you set in SET_TENANT_DATA

poi.getTenantBoothId()

getDisplayName

getTenantName or feature name

poi.getDisplayName()

hasName

check if tenant or feature have name.

poi.hasName()

getDisplayCategory

get first category of tenant or feature if there is category.

poi.getDisplayCategory()

hasCategories

check if tenant or feature have categories.

poi.hasCategories()

isBuilding

check if feature is building.

poi.isBuilding()

getIcon

getTenantIcon or feature icon

poi.getIcon()

getBoothId

getTenantBoothId or feature booth id

poi.getBoothId()

Advanced Scenrios (Look at sample for implementation of scenrios)

Highlight initial feature

if you dispatch SET_ZOOM/SET_CENTER

you should dispatch HIGHLIGHT_FEATURE for initial feature after ZOOM_ENDED/CENTER_ENDED

if you don't dispatch SET_ZOOM/SET_CENTER

you should dispatch HIGHLIGHT_FEATURE for initial feature after MAP_LOADED

Add custom buttons inside feature popup template

you should dispatch SET_DEFAULT_FEATURE_POPUP_TEMPLATE for your customized template and add your custom buttons and use dispatchToContainer when button clicked to handle the click action in your APP.

Important Notes

to fix map scrolling in new IOS devices add this line

webView.scrollView.scrollEnabled = false;

See it in code

Our default feature popup template

<md-card id="{{poi.id}}" class="feature-popup display-none slide-up">
  <div layout="row" layout-align="end start" >
    <md-card-title class="padding-bottom-overide" layout="row" layout-align="center center">
      <md-card-title-media ng-if="poi.getDisplayName()">
        <div class="circle" layout="row" layout-align="center center">
          <md-icon ng-if="!poi.getIcon()" md-font-set="material-icons" class="camera-icon">camera_alt</md-icon>
          <img ng-if="poi.getIcon()" ng-src="{{poi.getIcon()}}" />
        </div>
      </md-card-title-media>
      <md-card-title-text >
        <div class="md-subline">{{poi.getDisplayName() || poi.getDisplayCategory()}}</div>
        <div ng-if="poi.getBoothId()" layout="row">
          <div class="categoryline" >
            <div class="margin-right-margin-left">{{poi.getBoothId()}}</div>
          </div>
        </div>
        <div ng-if="poi.category" layout="row">
          <div class="categoryline" >
            <div class="margin-right-margin-left">{{poi.category}}</div>
          </div>
        </div>
      </md-card-title-text>
    </md-card-title>
    <md-button id="close-info" class="md-icon-button" ng-click="closeInfo()">
      <md-icon md-font-set="material-icons" aria-label="close info">close</md-icon>
    </md-button>
  </div>
  <md-card-actions layout="row" layout-align="center center" >
    <div ng-if="poi.category === 'wheelchair-bathroom'" layout="row" layout-align="center center">
      <i class="fa fa-3x fa-wheelchair"></i>
    </div>
    <!-- <md-divider></md-divider> -->

    <br ng-if="poi.category === 'wheelchair-bathroom'"  />
    <br ng-if="poi.category === 'wheelchair-bathroom'"  />
    <div flex ng-if="enableRouting && poi.entrances && poi.entrances.length" class="feature-routing-buttons" layout="row" layout-align="center center">
      <md-button layout="row" class="md-raised md-primary" ng-click="showRoutingDialog($event, {from: poi})">
        <div class="margin-right-margin-left"> Route From</div>
        <md-icon md-font-set="material-icons" >adjust</md-icon>
      </md-button>
      <md-button layout="row" class="md-raised md-primary" ng-click="showRoutingDialog($event, {to:poi})">
        <div class="margin-right-margin-left"> Route To</div>
        <md-icon md-font-set="material-icons" >flag</md-icon>
      </md-button>
    </div>
  </md-card-actions>
</md-card>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published