如何获取ios/Android中bing地图搜索地址的边界?

问题描述 投票:0回答:1

我正在使用地址名称搜索位置,并使用坐标获取此地址在 bing 地图上的位置。

但这只显示搜索位置的图钉。

但我的要求是在必应地图上获得搜索地址的完整边界。

我正在使用下面的代码

`

extension ViewController: GeocodeAlertDelegate {

func searchButtonTapped(query: String, culture: String, region: String, useLocation: Bool, useBoundingBox: Bool) {
    guard !query.isEmpty else {
        return
    }

    var referenceLocation: MSGeopoint?
    if useLocation {
        referenceLocation = self.mapView.mapCenter
    }
    var referenceBoundingBox: MSGeoboundingBox?
    if useBoundingBox {
        referenceBoundingBox = self.mapView.mapBounds
    }

    let options = MSMapLocationOptions()
    if !culture.isEmpty {
        options.setCulture(culture)
    }
    if !region.isEmpty {
        options.setRegion(region)
    }

    MSMapLocationFinder.findLocations(query, withReferencePoint: referenceLocation, withReferenceBoundingBox: referenceBoundingBox, with: options, handleResultWith: { (result: MSMapLocationFinderResult) in
        switch result.status {
        case MSMapLocationFinderStatus.success:
            self.pinLayer.elements.clear()
            let locations = NSMutableArray()

            for mapLocation in result.locations {
                let pinLocation = MSGeopoint(
                    latitude: mapLocation.point.position.latitude,
                    longitude: mapLocation.point.position.longitude,
                    altitude: 0,
                    altitudeReferenceSystem: MSMapAltitudeReferenceSystem.terrain)
                print("AddressName:- \(mapLocation.address)")
                print("DisplayName:- \(mapLocation.displayName)")

                self.addPin(atLocation: pinLocation, withTitle: mapLocation.displayName)
                locations.add(mapLocation.point)
            }
            
            if locations.count > 1 {
                self.mapView.setScene(MSMapScene(locations: locations as! [MSGeopoint]), with: MSMapAnimationKind.default)
            } else {
                self.mapView.setScene(MSMapScene(location: locations[0] as! MSGeopoint), with: MSMapAnimationKind.default)
            }
        case MSMapLocationFinderStatus.emptyResponse:
            self.showMessage("No result was found")
        default:
            self.showMessage("Error processing the request")
        }
    })
}
}

`

swift bing-maps xcode14.3
1个回答
0
投票

适用于 iOS 和 Android 的大地图服务库仅提供正向和反向地理编码功能。这些服务不提供对 Bing 地图中边界数据的访问。在必应地图中,必应空间数据服务的地理数据 API 是可用于检索边界的 REST 服务。要在您的应用程序中使用它,您需要向该 REST 服务发出请求并解析 JSON 响应和编码的边界数据,并将其转换为

MapPolygon
对象数组。请注意,边界服务通常会返回
MultiPolygons
,我认为
MapPolygon
类不直接支持它,因此您可能会为单个边界解析一组
MapPolygon
对象。

附带说明一下,Microsoft 的另一个地图平台 Azure Maps 具有具有更高级功能的本机 iOS 和 Android SDK。他们还有一个用于多种编程语言的 REST 服务的客户端库,但目前还不是很迅速。因此,如果您考虑到这一点,获取边界数据将需要使用该 SDK 进行类似的工作量。

© www.soinside.com 2019 - 2024. All rights reserved.