开发指南
获取KEY
- 创建应用
进入控制台,创建一个新应用。如果您之前已经创建过应用,可直接跳过这个步骤。


审核通过后,即可获取密钥 accessKey。
项目创建
工程配置
1. 打开/创建一个iOS工程
使用Xcode打开一个iOS工程,或者新建一个iOS工程
2. SDK导入
将解压后的wzLib.framework文件copy或拖拽到工程文件夹中,并在弹框中choose options for adding these files选择add to targets中选择您的工程
3. 权限配置
在项目的Info.plist添加定位权限申请,根据业务需求设置:
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>
<key>NSLocationWhenInUseUsageDescription</key>
<string>是否允许使用您的定位?</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>是否允许后台一直使用定位?</string>
4. 代码集成
第1步,引入文件:
import wzLib
第2步,初始化:
var mapViewDelegate: MapViewDelegate?
var wzClientOption: WzClientLocation?
init() {
mapViewDelegate = MapViewDelegate(mapViewState: self.mapViewState)
wzClientOption = WzClientLocation()
wzClientOption?.initKey(accesskey: "申请 KEY ")
wzClientOption?.callDelegate = self
}
获取位置信息
单次定位
iOS定位SDK提供单次定位的能力。具体使用方法如下:
// 开启单次定位
wzClientOption?.isLocateOnce = true
wzClientOption?.startLocation()
// 实现定位回调
struct ContentView: View, LocationDelegate {
func onReceivedLocation(wzLocation: LocationRes) {
print("onReceivedLocation:\(wzLocation)")
let lat = wzLocation.location.position.point.latitude
let lon = wzLocation.location.position.point.longitude
}
func onLocationError(msg: String) {
print("onLocationError:\(msg)")
}
}
持续定位
iOS定位SDK提供持续定位的能力。具体使用方法如下:
// 开启持续定位
wzClientOption?.isLocateOnce = false
wzClientOption?.interval = 5.0
wzClientOption?.startLocation()
// 实现定位回调
struct ContentView: View, LocationDelegate {
func onReceivedLocation(wzLocation: LocationRes) {
print("onReceivedLocation:\(wzLocation)")
let lat = wzLocation.location.position.point.latitude
let lon = wzLocation.location.position.point.longitude
}
func onLocationError(msg: String) {
print("onLocationError:\(msg)")
}
}
地理编码相关接口
正地理编码(地址转经纬度):
wzClientOption?.getGeocCode(address: "武汉市洪山区关山大道43号", city: "")
// 实现正地理编码回调
func onReceivedGeocode(result: [wzLib.GeocodeRes]) {
var details = "地理编码结果(共\(result.count)条):\n"
for (index, item) in result.enumerated() {
print("\n--- 第 \(index + 1) 条结果 ---")
print("名称:\(item.name)")
print("经纬度:\(item.geoPoint)")
print("完整地址:\(item.address.name)")
print("相关度:\(item.relevance)")
print("分类:\(item.categories?.first?.name ?? "无分类")")
}
print("onReceivedGeocode:\(details)")
}
逆地理编码(经纬度转地址):
wzClientOption?.getGeocCode(latitude: 21.706204, longitude: 108.380965)
// 实现逆地理编码回调(同正地理编码回调方法)
func onReceivedGeocode(result: [wzLib.GeocodeRes]) {
// 处理逆地理编码结果
}
POI搜索相关接口
POI关键字搜索:
wzClientOption?.poiKeySearch(name: "泛悦城", city_code: "", city: "武汉市", page_index: 1, page_size: 10)
// 实现POI搜索回调
func onReceivedPoiSearch(result: [wzLib.GeocodeRes]) {
var details = "POI搜索结果(共\(result.count)条):\n"
print("onReceivedPoiSearch:\(details)")
}
POI附近搜索:
wzClientOption?.poiNearbySearch(keywords: "学校", location: "114.414031,30.505642", radius: 1000, category: "", orderby: "", page_index: 1, page_size: 10)
// 实现POI搜索回调(同上)
func onReceivedPoiSearch(result: [wzLib.GeocodeRes]) {
// 处理POI附近搜索结果
}