我正在使用地址名称搜索位置,并使用坐标获取此地址在 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")
}
})
}
}
`