How to get boundary of searched address on bing map in ios/Android?

126 Views Asked by At

I am searching location with address name and fetching where this address is located on bing map with coordinate.

But this is only showing pin over searched location.

But my requirement is to get complete boundary of searched address on bing map.

I am using below code

`

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")
        }
    })
}
}

`

1

There are 1 best solutions below

0
On

The Big Maps services library for iOS and Android only expose forward and reverse geocoding capabilities. Those services do not provide access to boundary data in Bing Maps. In Bing Maps the Geodata API of the Bing Spatial Data Services is the REST service that can be used to retrieve boundaries. To use this in your app you would need to make a request to this REST service and parse the JSON response and the encoded boundary data and convert it to an array of MapPolygon objects. Note that the boundary service often returns MultiPolygons which I don't believe are supported directly by the MapPolygon class, thus why you would likely parse an array of MapPolygon objects for a single boundary.

As a side note, Microsoft's other mapping platform, Azure Maps has native iOS and Android SDKs that have more advanced capabilities. They also have a client-libraries for their REST services for multiple programming languages, but not currently swift. So if you were considering that, getting the boundary data would require a similar amount of work with that SDK.