Mapwize UI iOS
功能齐全且准备好使用的 UIView,可添加 Mapwize 室内地图和导航到您的 iOS 应用程序中。
它是开源的 !
有关 MWZVenue、MWZPlace、MWZOptions 等Mapwize SDK 对象的文档,请参阅 docs.mapwize.io 上的 Mapwize SDK 文档。
描述
Mapwize UI 视图包含以下组件:
- Mapwize SDK 集成
- 楼层控制器
- 跟随用户按钮
- 搜索模块
- 方向模块
- 地点选择
- 宇宙按钮
- 语言按钮
安装
MapwizeUI 与 MapwizeForMapbox 3.0.0 及以上版本兼容。库不会与更低版本一起工作。
Cocoapod
将 MapwizeUI 库添加到您的 Podfile 中
pod 'MapwizeUI', '~> 2.0'
然后运行 pod install
将安装所有依赖项(MapwizeUI、MapwizeForMapbox、Mapbox 和 IndoorLocation)
手册
- 克隆 Github 仓库
- 将 MapwizeUI 项自复制到您的应用项目中
初始化
API 密钥
您需要 Mapwize API 密钥来加载地图和允许 API 请求。只需在您的 info.plist 中添加带密钥的 MWZApiKey。
要获取自己的 Mapwize API 密钥,请前往 mapwize.io 注册免费账户。然后在 Mapwize Studio 中,转到侧菜单的 "API Keys"。
Mapbox 配置
要在您的设备上运行 Mapbox,您需要在您的 info.plist 文件中添加以下元素
- MGLMapboxAccessToken -> pk.mapwize
- MGLMapboxMetricsEnabledSettingShownInApp -> YES
第一个使其可以加载 Mapwize 风格,第二个则确保我们为 Mapbox 提供了所需信息。使用这些设置,当用户点击地图左下角的 Mapwize 徽标时,将显示一个弹出窗口。
MWZMapwizeView
嵌套 MWZMapwizeView 的 UIView 必须实现 MWZMapwizeViewDelegate
并包含以下方法
- (void) mapwizeViewDidLoad:(MWZMapwizeView*) mapwizeView;
- (void) mapwizeView:(MWZMapwizeView*) mapwizeView didTapOnPlaceInformationButton:(MWZPlace*) place;
- (void) mapwizeView:(MWZMapwizeView*) mapwizeView didTapOnPlaceListInformationButton:(MWZPlaceList*) placeList; --> why not (id<MWZObject>) mapwizeObject
- (void) mapwizeViewDidTapOnFollowWithoutLocation:(MWZMapwizeView*) mapwizeView;
- (void) mapwizeViewDidTapOnMenu:(MWZMapwizeView*) mapwizeView;
- (BOOL) mapwizeView:(MWZMapwizeView*) mapwizeView shouldShowInformationButtonFor:(id<MWZObject>) mapwizeObject;
MWZMapwizeView 可以使用以下构造函数实例化
- (instancetype) initWithFrame:(CGRect)frame
mapwizeOptions:(MWZUIOptions*) options
uiSettings:(MWZMapwizeViewUISettings*) uiSettings;
- (instancetype) initWithFrame:(CGRect)frame
mapwizeConfiguration:(MWZMapwizeConfiguration*) mapwizeConfiguration
mapwizeOptions:(MWZUIOptions*) options
uiSettings:(MWZMapwizeViewUISettings*) uiSettings;
MWZMapwizeViewUISettings 包含以下属性
@property (nonatomic, retain) UIColor* mainColor;
@property (nonatomic, assign) BOOL menuButtonIsHidden;
@property (nonatomic, assign) BOOL followUserButtonIsHidden;
访问 MWZMapView
一旦调用了 (void) mapwizeViewDidLoad:(MWZMapwizeView*) mapwizeView
,您就可以使用 mapwizeView.mapView
来检索 MWZMapView
@property (nonatomic) MWZMapView* mapView;
简单示例
MWZOptions* opts = [[MWZOptions alloc] init];
MWZUISettings* settings = [[MWZUISettings alloc] init];
self.mapwizeView = [[MWZMapwizeView alloc] initWithFrame:self.view.frame
mapwizeOptions:opts
uiSettings:settings];
self.mapwizeView.delegate = self;
[self.view addSubview:self.mapwizeView];
定位到场所
要让地图在启动时定位到一个场所
MWZOptions* opts = [[MWZOptions alloc] init];
opts.centerOnVenueId = @"YOUR_VENUE_ID";
MWZUISettings* settings = [[MWZUISettings alloc] init];
self.mapwizeView = [[MWZMapwizeView alloc] initWithFrame:self.view.frame
mapwizeOptions:opts
uiSettings:settings];
定位到地点
要让地图在启动时定位到一个地点并且选中该地点
MWZOptions* opts = [[MWZOptions alloc] init];
opts.centerOnPlaceId = @"YOUR_PLACE_ID";
MWZUISettings* settings = [[MWZUISettings alloc] init];
self.mapwizeView = [[MWZMapwizeView alloc] initWithFrame:self.view.frame
mapwizeOptions:opts
uiSettings:settings];
地图选项
以下参数可用以初始化地图
centerOnVenueId
在启动时定位到一个场所。centerOnPlaceId
在启动时定位到一个地点。floor
在进入场所时设置默认楼层。楼层是 Double 类型的,可以是小数。使用 centerOnPlace 时忽略。language
设置场所的默认语言。它是一个包含该语言 2 个字母代码的字符串。例如:"fr" 或 "en"。universeId
设置显示场所的默认宇宙。如果使用 centerOnPlace,则需要是一个包含该地点的宇宙。restrictContentToVenueId
在地图上仅显示相关场所。restrictContentToVenueIds
在地图上仅显示指定的场所。restrictContentToOrganizationId
在地图上仅显示该组织的场所。
公共方法
友好的方法用于添加对新地图的访问并刷新UI - (void) grantAccess:(NSString*) accessKey success:(void (^)(void)) success failure:(void (^)(NSError* error)) failure;
设置UI以显示所选位置的信息,推广位置并为其添加标记 - (void) selectPlace:(MWZPlace*) place centerOn:(BOOL) centerOn;
设置UI以显示所选位置列表的信息,在位置列表中的位置上添加标记并推广它们 - (void) selectPlaceList:(MWZPlaceList*) placeList;
隐藏UI组件、移除标记并在需要时取消推广位置 - (void) unselectContent:(BOOL) closeInfo;
显示方向对象并显示已配置的方向UI
- (void) setDirection:(MWZDirection*) direction
from:(id<MWZDirectionPoint>) from
to:(id<MWZDirectionPoint>) to
directionMode:(MWZDirectionMode*) directionMode
位置详情
位置详情为您提供了一个可自定义的、现成的UI。您可以完全控制显示的按钮和行。
您可以使用以下回调来控制详情UI中的按钮和行。
/**
Called when the bottom view is going to be displayed
The MapwizeUI SDK build all component that will be displayed in the view and give it back to the developper through this method's components argument.
You can change, remove or add component in the MWZUIBottomSheetComponents and return it.
The returned MWZUIBottomSheetComponents will be used to display the final content.
@param mapwizeView the view that called the methode
@param placeDetails the placeDetails object about to be displayed in the bottom view
@param components the components build by the SDK based on the info contains in the object.
*/
- (MWZUIBottomSheetComponents* _Nonnull) mapwizeView:(MWZUIView* _Nonnull) mapwizeView requireComponentForPlaceDetails:(MWZPlaceDetails* _Nonnull)placeDetails withDefaultComponents:(MWZUIBottomSheetComponents* _Nonnull)components;
您将收到一个按钮列表,您可以修改它们、更改它们的顺序或删除其中的一些。
在调用 requireComponentForPlaceDetails
之前会调用 shouldDisplayInformationButton
回调。 requireComponentForPlaceDetails
回调将是关于行或按钮显示的最终决定者。
管理按钮
您可以使用 MWZUIIconTextButton
构造函数创建一个小的按钮对象 - (instancetype)initWithTitle:(NSString*) title image:(UIImage*) image color:(UIColor*) color outlined:(BOOL) outlined;
您可以使用 MWZUIFullContentViewComponentButton
构造函数创建一个大的按钮对象 - (instancetype)initWithTitle:(NSString*) title image:(UIImage*) image color:(UIColor*) color outlined:(BOOL) outlined;
管理行
您可以通过以下方式创建行对象: MWZUIFullContentViewComponentRow
构造函数 - (instancetype) initWithImage:(UIImage*)image contentView:(UIView*)contentView color:(UIColor*)color tapGestureRecognizer:(nullable UITapGestureRecognizer*)tapGestureRecognizer type:(MWZUIFullContentViewComponentRowType)type infoAvailable:(BOOL) infoAvailable
信息按钮
当用户通过点击地图或使用搜索引擎选择一个地点或地点列表时,您可能希望为用户打开一个关于该地点的页面。例如,商店或参展商,您的应用可能有关于这些地点的详细信息页面。
提出的解决方案是在Mapwize视图中底部视图显示“信息”按钮。
可以使用 shouldShowInformationButtonFor
代理方法来说明是否显示按钮。对于给定的Mapwize对象返回true以显示按钮。
- (BOOL) mapwizeView:(MWZMapwizeView*) mapwizeView shouldShowInformationButtonFor:(id<MWZObject>) mapwizeObject;
示例:仅对地点显示信息按钮,而不对地点列表显示
- (BOOL) mapwizeView:(MWZMapwizeView *)mapwizeView shouldShowInformationButtonFor:(id<MWZObject>)mapwizeObject {
if ([mapwizeObject isKindOfClass:MWZPlace.class]) {
return YES;
}
return NO;
}
类似的方法可用于根据楼层列表显示或隐藏楼层控制器,并监听宇宙更改事件。
- (BOOL) mapwizeView:(MWZMapwizeView*) mapwizeView shouldShowFloorControllerFor:(NSArray<MWZFloor*>*) floors;
- (void) mapwizeUniverseHasChanged:(MWZUniverse*)universe; __attribute__((deprecated("Use MWZMapViewDelegate instead")));
当点击信息按钮时,代理将调用以下方法之一并传递选定的Mapwize对象。
- (void) mapwizeView:(MWZMapwizeView*) mapwizeView didTapOnPlaceInformationButton:(MWZPlace*) place;
- (void) mapwizeView:(MWZMapwizeView*) mapwizeView didTapOnPlaceListInformationButton:(MWZPlaceList*) placeList;
颜色
您可以通过使用UISettings.mainColor属性来更改带有颜色的UI视图的颜色。
翻译
视图中包含一些可能需要翻译或更改的字符串。您可以在您的 strings.xml
文件中覆盖它们,并添加其他Localizable.strings文件以支持不同的语言。
"Direction" = "Direction";
"Information" = "Information";
"Search a venue..." = "Search a venue...";
"Entering in %@..." = "Entering in %@...";
"Search in %@..." = "Search in %@...";
"Destination" = "Destination";
"Starting point" = "Starting point";
"Current location" = "Current location";
"No results" = "No results";
"Floor %@" = "Floor %@";
"Universes" = "Universes";
"Choose an universe to display it on the map" = "Choose a universe to display it on the map";
"Languages" = "Languages";
"Choose your preferred language" = "Choose your preferred language";
"Cancel" = "Cancel";
"Direction not found" = "Direction not found"
"Search error" = "Search went wrong"
"Search" = "Search"
请小心处理包含占位符的字符串。请确保保持确切的占位符!例如,如果您将“Floor %@”替换为“我的楼层”而不保留占位符,则您的应用程序会崩溃。
示例应用程序
本仓库提供了一个演示应用程序,可以快速测试UI。您需要开始的一切就是Mapwize API密钥。您可以通过在mapwize.io上注册免费账户来获取密钥。
一旦您拥有API密钥,请将其添加到info.plist文件中,密钥名为MWZMapwizeApiKey
要进一步测试UI,请转到ViewController并更改一些选项或在其中添加一些代码。
分析
Mapwize SDK和Mapwize UI没有内置分析跟踪器。这意味着Mapwize不知道地图在您的应用程序中的使用情况,我们认为这对于隐私来说是个好事。这也意味着Mapwize无法为您提供分析指标,如果您需要,您将不得不使用自己的分析跟踪器对代码进行配置。
可以通过使用以下事件来使用来自MWZUIViewDelegate
的事件和回调检测界面变化并触发跟踪事件。我们认为使用以下事件是有意义的:
venueDidEnter
venueDidExit
floorDidChange
universeDidChange
languageDidChange
didSelectPlace
didSelectPlacelist
didStartDirectionInVenue