WoosmapIndoor 1.0.14

WoosmapIndoor 1.0.14

Operationssameer dhulapWoosmap 维护。



  • Web Geo Services

woosmap

Woosmap Indoor SDK

Woosmap Indoor SDK 为 iOS 开发者创建室内定位应用程序提供帮助。(以下简称“SDK”具有以下特性)

  1. 可用于 Google 室内地图或自定义地图。
  2. 带有逐个转弯指令的方式进行路径导航。
  3. 无缝楼层过渡,可以选择使用内置楼层选择器,或与用户自定义的楼层选择器一起工作。
  4. 在场所内搜索产品和地点。
  5. 在地理围栏区域触发附近警报,用于优惠或广告。

设置

本节涵盖了 SDK 集成。

系统需求

  • Xcode 版本 11.0 或更高版本
  • iOS 12.0 或更高版本

创建SDK客户端项目 首先使用“Single View Application”模板创建一个新的普通Xcode项目。您可以选择Swift或Objective-C。SDK可以与两者无缝协作。

使用CocoaPods下载SDK(推荐)

  1. 在项目目录中创建一个名为PodFile的文件。

  2. 编辑Podfile并添加WoosmapIndoor SDK依赖项。以下是一个添加依赖项源'https://github.com/Woosmap/woosmapindoor.git',使用_frameworks! pod 'WoosmapIndoor'

  3. 保存Podfile。

  4. 打开终端并转到包含Podfile的目录。

  5. 运行pod install命令。

  6. 关闭Xcode。从此以后,使用项目的.xcworkspace文件打开项目。

手动下载和设置SDK(不推荐)

如果您的项目无法使用CocoaPods,您可以选择手动将SDK添加到您的项目中。为实现此目的,从<<GitHub https://github.com/Woosmap/woosmapindoorsdk.git>>下载SDK的最新版本并添加到您的Xcode项目中。

添加Google Maps SDK

需要将Google Maps SDK添加到项目中以渲染地图。通过CocoaPods添加Google Maps SDK的步骤与上述添加WoosmapIndoor SDK的步骤类似。您的PodFile应如下所示

  source 'https://github.com/CocoaPods/Specs.git'
  source 'https://github.com/Woosmap/woosmapindoor.git'
  use_frameworks!
  pod 'WoosmapIndoor'
  pod 'GoogleMaps'

授权 每个使用WoosmapIndoor SDK的应用程序都需要一个唯一的MapAPIKey来使用其服务。此密钥将在SDK为您的应用程序激活后提供给您。在您的项目appdelegate类中,使用import WoosmapIndoor导入SDK。在AppDelegate的application:didFinishLaunching方法中实例化WoosmapIndoorService实例。请参见下面的示例。

  WoosmapIndoorService.provideAPIKey("<<MapAPIKey>>", andGMSMapKey: "<<GoogleMapsKey>>")

开发者指南

在应用程序中显示您的第一个地图

SDK的核心组件是IndoorMap类。地图事件会传递到其代理,该代理应遵循IndoorMapDelegate协议。

要加载应用内部的场所地图,请按照以下步骤操作

  • 在您的ViewController类文件中,使用import WoosmapIndoor导入框架头文件。
  • 添加IndoorMapDelegate代理。
  • 创建IndoorMap类的实例并将代理指向接收者。
  • 在ViewController的viewDidLoad方法中使用以下代码行加载场所地图。

以下是一个代码片段

import WoosmapIndoor    
class ViewController: UIViewController,IndoorMapDelegate{
  var IndoorMap: IndoorMap = IndoorMap.init()
  override func viewDidLoad() {
      super.viewDidLoad()
      IndoorMap.view.frame = self.vwMap.bounds
      IndoorMap.mapdelegate = self
      IndoorMap.VenueID=<<VenueID>>; //The VenueID will be provided to you when you activate the SDK.
      IndoorMap.enableFloorSelector = false
      vwMap.addSubview(IndoorMap.view)
      IndoorMap.autoFit() //This will resize map for size of container
    }

与地图交互

IndoorMapDelegate 协议向客户端应用程序公开用于与地图交互的事件。具体包括以下内容

  • 地图上的长按
func indoor(_ mapView: Any, didLongPressAt coordinate: CLLocationCoordinate2D, floor level: Int32) {
    //coordinate consists of the location where there was a long press
    //level indicates the active floor where the long press event was called
}
  • 地图上的单一点击
func indoor(_ mapView: Any, didTapAt coordinate: CLLocationCoordinate2D, floor level: Int32){
//coordinate consists of the location user did a single tap on map
//level indicates the active floor where the single tap event was called
}
  • 标记窗口上的单一点击
func indoor(_ mapView: Any, didTapInfoWindowOfMarker markerDetail: [AnyHashable : Any]){
}

地图上查找POI

要在地图上搜索POI,请使用findPOI方法。此方法在地图中搜索给定的商家id。在回调中返回包含POI信息的字典对象。如果未找到POI,则返回错误对象。

地图上突出显示/取消突出显示POI

使用showPOIMarker方法在特定的POI处显示标记。此方法接受字典对象形式的POI信息以及一个UIView类的对象,该对象在地图上作为标记进行渲染。

路径搜索

要显示两点之间的路径,应调用SDK的findRoute:方法。

IndoorMap.findRoute(sourcePoint destination:destination)

此方法通过在源点和目的地点之间绘制路径以显示路径预览模式。调用上述方法将触发代理的,indoor:route:事件。客户端应用程序需要监听此事件以收集在该路径中找到的多个点之间的数据。

func indoor(_ mapView: Any, noRoute routeList: [Any]!){
  //routeList consists of a GeoJSON feature collection.
  //Any additional UI elements to be performed can be added here.
}

两点之间渲染的路径是可定制的。为了更改要渲染路径的外观和感受,在实例化 IndoorMap 类对象后,在 ViewController 的 viewDidLoad 方法中使用以下代码片段。请参阅以下代码片段。

IndoorMap.pathOptions={ formatter in
  format.pathColor = UIColor.red //To change the path color.
  format.pathWidth = NSNumber(value: 8.0)//Sets the width of the path
  format.borderColor = UIColor(red: 0.247, green: 0.000, blue: 0.002, alpha: 1.000) //Sets the bordercolor for the path.
  format.borderWidth = NSNumber(value: 4.0) //Sets the border width for the path.
  format.SelectedPathColor = UIColor.white //Sets the selected path color.
  return format
  }

多站点路线查找

多站点路线查找是一种特性,SDK 会从起始位置和提供的点列表中绘制最短路径。要显示多站点行程路径,应调用 findRoute 方法的重载形式。

  -(void)findRoute:(CGIndoorMapPoint)startPoint destinations:(NSArray<Stopover *> *_Nonnull)endPoints;

上述函数接受起点和 Stopover 对象数组。调用此方法也将触发代理的,indoor:route: 事件。正如在查找两点之间的路径时那样。请注意,目前多站点行程最多只能有六个停歇点。以下屏幕截图显示了多站点行程如何在地图上渲染。

以下代码片段显示了多站点行程的一个示例调用。

private func plotStopOverList(){
      let stopover1 = Stopover();
      stopover1.mapPoint = CGMakeMapPoint(59.91902645797848,10.585014671087265,0)
      stopover1.title = "Pizza"
      let stopover2 = Stopover();
      stopover2.mapPoint = CGMakeMapPoint(59.91900561998954,10.585307031869888,0)
      stopover2.title = "Pickles"
      let stopover3 = Stopover();
      stopover3.mapPoint = CGMakeMapPoint(59.918976883709114,10.585519932210445,0)
      stopover3.title = "Ice-cream"
      let stopover4 = Stopover();
      stopover4.mapPoint = CGMakeMapPoint(59.91903032308789,10.58555044233799,0)
      stopover4.title = "Sweets"
      let stopover5 = Stopover();
      stopover5.mapPoint = CGMakeMapPoint(59.91907485583784,10.585437454283237,0)
      stopover5.title = "Baby Food"
      let stopover6 = Stopover();
      stopover6.mapPoint = CGMakeMapPoint(59.919056874696935,10.585566200315952,0)
      stopover6.title = "Sanitary"
      let currentUserLocation = IndoorMap.userLocation() if(!CGIndoorMapPointIsEmpty(currentUserLocation)){
            SwiftLoader.show(animated: true)
            IndoorMap.findRoute(currentUserLocation, destinations: [stopover1,stopover2,stopover3,stopover4,stopover5,stopover6])?? "")")
            lblStoreName.text = "Shopping list"
            lblEndPoint.text = LocalizedString("To \(lblStoreName.text
            showNavigationDetail(true, animation: true) changeTopBarForNavigation()
} else {
  //Please Select your location on map
  let alert = UIAlertController(title: "", message: "Please location on map and try again", preferredStyle:UIAlertController.Style.actionSheet)
  let doneAction : UIAlertAction = UIAlertAction(title: "OK", style: .default) { (alertAction) in
  }
  alert.addAction(doneAction)
  self.present(alert, animated: true, completion: nil)
}

在多站点路线查找中自定义停歇标记

您可以使用 addCustomePOI 方法来自定义停歇标记。以下代码示例可用于在每个停歇点添加自定义标记。

let pointTrack = TrackingMarker()
pointTrack.position = CLLocationCoordinate2DMake(pointCoordinate[1], pointCoordinate[0])
pointTrack.level = NSNumber(0)
pointTrack.title = waypoint
let listIndexView = ShoppingListIndexView() listIndexView.createUI(shoppingListCounter)
pointTrack.iconView = listIndexView.view //New Icon created from XIB pointTrack.groundAnchor = CGPoint(x: 0.5, y: 1.0)
pointTrack.isFlat = false
pointTrack.zIndex = 999
IndoorMap.addCustomePOI(pointTrack)

基于标签的路线查找

基于标签的路线查找是一种方式,用于定义每种路径哪种类型的人可以使用它从地点导航到目的地。机场等场所内典型路线标签的例子包括:

  • 安全人员
  • 维护人员
  • 行动不便的人
  • 乘客

在机场等场所,上述人群走的路径可能不同,因为某些路径可能仅限于某些人。

这些标签是为每个场所预先定义的,并在创建场所时创建。开发者不能在运行时创建这些标签。可在 IndoorSettings 对象中访问可用标签列表。

func indoor(_ sender: Any, onLoaded isLoaded: Bool) {
  let avalibleRoutingOptions = IndoorSettings.instance().getRouteTags()
}        

IndoorSettings.instance().getRouteTags() 返回一组 RouteTag 对象列表。每个对象代表在场所中定义的一个路由标签。RouteTag 对象可传递给室内地图寻路方法,该方法将为指定的标签返回路径。

下例展示了如何在使用两点之间的路由时使用路由标签。

indoorMapObj.routeTags = selectedRoutingOptions[0]

indoorMapObj.findRoute(startLocation, destination: endLocation)  

或者

indoorMapObj.pathOptions={ format in
      if let pathFormatOptions = format{
          pathFormatOptions.pathColor = UIColor.red //To change the path color.
          pathFormatOptions.pathWidth = NSNumber(value: 8.0)//Sets the width of the path
          pathFormatOptions.borderColor = UIColor(red: 0.247, green: 0.000, blue: 0.002, alpha: 1.000) //Sets the bordercolor for the path.
          pathFormatOptions.borderWidth = NSNumber(value: 4.0) //Sets the border width for the path.
          pathFormatOptions.routeTag = selectedRoutingOptions[0]
          return pathFormatOptions
      }
      return format
    }

    indoorMapObj.findRoute(startLocation, destination: endLocation)     

显示带有转向指示的路线

为了显示带有转向指示的路线,客户端应用程序应调用 SDK 的 startNavigation() 方法。此处的 NavigationMode 将为 Navigation_TurnByTurn。请看下面的代码片段。

   IndoorMap.startNavigation()

客户端应用程序应监听代理的 instruction: 方法,以获取在该路线上找到的每个地点的逐步指示。

func indoor(_ mapView: Any, instruction pathIndex: UInt, pathInfo routeInfo: [AnyHashable : Any]!){
//routeInfo will have a dictionary of the current step instruction.
}

要浏览指令步骤集,可以使用 SDK 的 nextStepInstruction()peviousStepInstruction() 方法。

IndoorMap.nextStepInstruction() //Gets next step instruction.
IndoorMap.previousStepInstruction() //Gets previous step instruction.

上述两种方法都会随后调用上述代理的 instruction: 方法。

寻路和导航回调

IndoorMapDelegate 接口引发与寻路和导航相关的回调。以下是一些:

回调 描述
-(void)indoor:(id)mapView route:(NSArray *)routeList 当寻路成功执行 return 路径到应用程序时调用。
-(void)indoor:(id)mapView noRoute:(NSArray *)routeList 当寻路成功执行但找不到任何适合路径时调用。
-(void)indoor:(id)mapView onNavigationError:(NSError *)errorInfo 当 Woosmap Indoor cloud 平台找不到路径时调用。
-(void)indoor:(id)mapView endNavigation:(BOOL)navigationState destinationDirection:(DestinationDirection)atDirection 当用户到达寻路目的地的目的地时调用。
func indoor(_ mapView: Any, navigationExited navigationState: Bool) 当用户明确定义退出寻路时调用。
-(void)indoor:(id)mapView instruction:(NSUInteger)pathIndex pathInfo:(NSDictionary *)routeInfo 当用户比其他路径段更接近一个路径段时调用。此监听器还将在用户切换到预览模式时调用。公开两个参数,pathIndex:路径段的位置。routeInfo:当前路径段详细信息。
-(void)indoor:(id)mapView reRouteWithLocation:(CLLocationCoordinate2D)coordinate floor:(int)level 当用户偏离路径时调用。
-(void)indoor:(id)mapView navigationInterrupted:(BOOL)coordinate 当用户明确定义更改当前段时调用。这可能在用户使用 navigationPager 浏览当前寻路路的指令时发生。
-(void)indoor:(id)mapView onFloorChange:(int)level triggerByUserInteaction:(BOOL)isByUser 这个回调在渲染楼层更改标记之前调用。使用此方法创建您自己的楼层更改标记。您可以膨胀并返回自己的视图作为楼层更改标记。返回null以使用默认标记。
-(void)indoor:(id)mapview onNavigationStatusUpdated:(NSDictionary *)navigationParams 此回调在用户的位置在导航模式下更新时触发。

在多楼层之间切换

您可以在应用程序中使用内置的楼层选择器或创建自己的楼层选择器。要禁用内置的楼层选择器,请将IndoorMap类的enableFloorSelector属性设置为NO。请参阅下面的代码片段

  IndoorMap.enableFloorSelector=false; //true to use in-built floor selector.

如果使用自定义楼层选择器,则需要将楼层号传递给SDK的changeFloor()方法以切换到相应楼层的地图。

   IndoorMap.changeFloor(floor)

当发生楼层更改事件时,SDK将通知已注册的客户端应用程序的代理的onFloorChange:方法。

  func indoor(_ mapView: Any, onFloorChange level: Int32){
  }

检测用户靠近扶梯/电梯

SDK可以通过其onEnterFloorChangeRegiononExitFloorChangeRegion代理方法通知客户端应用程序用户进入/退出扶梯/电梯区域。如果客户端应用程序需要添加任何功能,则当用户发现靠近最近的电梯/扶梯时,可以按照以下方式实现

func indoor(_ mapView: Any, onEnterFloorChangeRegion region: [AnyHashable : Any]!){
//Called when user found near Escalator/Elevator area.
//region consists of an NSDictionary of the elevator/escalator near to the user
}

启用搜索

SDK提供将搜索添加到您的应用程序的功能。可以使用几行代码在场馆内搜索POI、便利设施(洗手间、ATM、咖啡馆和信息台)。SDK的MapSearch类是执行应用程序内搜索操作的中央组件。搜索事件通过符合MapSearchDelegate协议的MapSearch的代理传递。要在客户端项目中使用SDK实现搜索,请按照以下步骤操作

  • 在您的ViewController类文件中,使用import WoosmapIndoor导入框架头文件。

  • 添加MapSearchDelegate代理。

import WoosmapIndoor
class SearchViewController : UIViewController, MapSearchDelegate{
      var poiSearch: MapSearch = MapSearch.init(SearchType.POI)
      var aminitySearch: MapSearch = MapSearch.init(SearchType.amenity)
}

注意:我们创建了两个独立的MapSearch类实例,一个用于POI搜索,另一个用于设施搜索。MapSearch构造函数接受一个SearchType常量。SearchType的值可以是Search_POISearch_Amenity

  • 使用其便利构造函数创建MapSearch类实例,并将委托指向接收器。
override func viewDidLoad(){
    poiSearch.mapSearchDelegate = self
    aminitySearch.mapSearchDelegate = self
}
  • 调用MapSearch类的searching:方法以执行搜索。
  poiSearch.searching(<<text to search>>)
  • 实现MapSearchDelegate协议searchDidStartLoad:searchDidFinishLoad:方法。当客户端应用程序调用MapSearch类的searching:方法时,SDK将通过触发MapSearchDelegate的searchDidStartLoad:方法来通知客户端应用程序。
func searchDidStartLoad(_ sender: MapSearch?){
  //Showing custom progress bar or any other additional functionality can be implemented over.
}

当SDK准备好搜索结果时,它将通过触发MapSearchDelegatesearchDidFinishLoad:方法来通知客户端应用程序。

func searchDidFinishLoad(_ sender: MapSearch!, result response: [Any]!){
  //response will an NSArray of results returned from the SDK for the application’s search operation.
  // Additional functionality of binding the search results can be implemented over here.
}

在地图上突出显示多个POI

SDK支持以标记的形式显示搜索结果。为了实现这一点,已公开了以下新方法和回调。

func showSearchedPOIs(onMap searchresult: [Any]?, completion result: @escaping (_ searchResult: [Any]?, _ error: Error?) -> Void) {
}
  • func showSearchedPOIs(onMap searchresult: [Any]?, completion result: @escaping (_ searchResult: [Any]?, _ error: Error?) -> Void):此方法接受一个包含POI id的String数组,并返回包含在地图上突出显示的POI id的String数组。突出显示的POI将显示为标记。当搜索结果显示在地图上时,其他POI(即未传递到此函数的POI)将被禁用。它们会淡化,并且与它们的交互将被禁用。
  • func indoor(_ mapview: Any, onSearchedPOISelected poiinfo: [Any : Any]?):已添加了一个新事件。此事件在用户点击任何已搜索/突出显示的POI时触发。
  • func clearSearchedPOIs():顾名思义,此方法将搜索结果从地图中清除。POI图标将返回到原始状态。

地理围栏区域的近距离警报

WoosmapIndoor SDK允许您设置您场地的近距离警报。一旦通过我们的后端服务设置完您场地的地理围栏区域,您的应用程序就准备好通过几行代码接收作为应用内通知的近距离警报。

当用户的定位在场地内的任何地理围栏区域内时,SDK将通知客户端应用程序。

客户端应用程序需要实现委托的enterPromoZone:方法以接收SDK的通知。

func indoor(_ mapView: Any, enterPromoZone Zone: [AnyHashable : Any]!, promotion offers: [Any]!){
  //Zone consists of NSDictionary of the geo-fenced area in which the user is found
  //offers consists of NSArray of all the active offers found in the geo-fenced zone.
}

SDK 还能识别用户何时退出地理围栏区域,并可以通过 IndoorMapDelegateexitPromoZone: 方法通知客户端应用程序。

func indoor(_ mapView: Any, exitPromoZone Zone: [AnyHashable : Any]!){
  //Zone consists of NSDictionay of the zone from where the user makes an exit.
}

可自定义元素

SDK 向客户端应用程序提供了自定义地图上渲染的某些元素的功能。客户端应用程序可以使用自己的资产来自定义以下元素的样式和外观。

# 可自定义 元素名称
1 蓝色圆点 - 用户当前位置 blue-dot.png (请将其添加到应用程序资源文件夹中)
2 路由 - 起始标记 func indoor(_ mapview: Any, customizeEndMarker imgPin: UIImage?) -> UIView?
3 路由 - 结束标记 func indoor(_ mapview: Any, customizeStartMarker imgPin: UIImage?) -> UIView?
4 路由 - 楼层变换指标标记 func indoor(_ mapview: Any, customizeLevelChangedMarker imgPin: UIImage?, mode floorChangeMode: FloorConntectedBy, movingUp up: Bool) -> UIView?
5 导航头箭头 indoorMapObj.setNavigationHeadMarker(UIImage.init(named: "arrowHead"))indoorMapObj.hideNavigationHeadMarkerOnLastStep = True
6 导航头箭头可见性 indoorMapObj.hideNavigationHeadMarkerOnLastStep = True/ False

API参考资料

Woosmap室内地图iOS SDK参考资料

许可证

© 2021-2022 Web Geo Services. 版权所有。