Compartilhar via


Scenes and Cameras

Note

Bing Maps SDK for Android and iOS retirement

Bing Maps SDK for Android and iOS is deprecated and will be retired. Free (Basic) account customers can continue to use Bing Maps SDK for Android and iOS until June 30th, 2025. Enterprise account customers can continue to use Bing Maps SDK for Android and iOS until June 30th, 2028. To avoid service disruptions, all implementations using Bing Maps SDK for Android and iOS will need to be updated to use Azure Maps Web SDK by the retirement date that applies to your Bing Maps for Enterprise account type.

Azure Maps is Microsoft's next-generation maps and geospatial services for developers. Azure Maps has many of the same features as Bing Maps for Enterprise, and more. To get started with Azure Maps, create a free Azure subscription and an Azure Maps account. For more information about azure Maps, see Azure Maps Documentation. For migration guidance, see Bing Maps Migration Overview.

Because the Map View can show both oblique and nadir views, as well as 3D topology, it is important to carefully set your view so that obstacles, such as mountains, do not get in your way.

To help with this, the Bing Maps native controls support the concept of scenes as a primary tool for establishing a view.

Via the MapScene static methods, you can establish different perspectives and the map will automatically choose the best camera for that perspective based on environmental factors, including the user's current view within the map.

Examples

Set the initial location of a map

The following example shows how to set the starting location of an map using setScene. This sets the map to be zoomed in over London, UK on start up.

Swift

override func viewDidLoad() {
    super.viewDidLoad()

    mapView.credentialsKey = "credentials here"
    let scene = MSMapScene(location: MSGeopoint(latitude: 51.50632, -0.12714), zoomLevel: 10))
    self.mapView.setScene(scene, with: .none)
}

Handle completion after the camera arrives

The following example shows how to move the camera to Seattle with a default animation and handle the animation being complete.

Swift

    // Set map to seattle asynchronously
    func setMapToSeattle() {
        // Specify a known location.
        let cityPosition = MSGeopoint(latitude:47.604, longitude:-122.329)
        let scene = MSMapScene(location: cityPosition, zoomLevel: 12)
        mapView.businessLandmarksVisible = true

        // Set the map location and
        mapView.beginSetScene(scene, with: .default, withCompletionCallback: {_ in
            // add code here to run scenario after the camera arrives at your destination
        })
    }

Show the location and a radius of 1000 meters around the location. Animate to it with a linear style animation

Java

mMap.setScene(MapScene.createFromLocationAndRadius(new Geopoint(47.599025, -122.339901), 1000), MapAnimationKind.LINEAR);

Swift

let scene = MSMapScene(location: MSGeopoint(latitude:47.599025, longitude:-122.339901), radius:1000);
mapView.setScene(scene, with: .linear)

Objective-C

MSMapScene *scene = [MSMapScene sceneWithLocation:[MSGeopoint geopointWithLatitude:47.599025 longitude:-122.339901]
                                           radius:1000];
[self.mMap setScene:scene withAnimationKind:MSMapAnimationKindLinear]

Show an area on the screen

Java

GeoboundingBox seattle = new GeoboundingBox(new Geoposition(47.599025, -122.339901), new Geoposition(47.589908, -122.313251));
mMap.setScene(MapScene.createFromBoundingBox(seattle), MapAnimationKind.LINEAR);

Swift

let seattle = MSGeoboundingBox(northwestCorner: MSGeoposition(latitude:47.599025, longitude:-122.339901),
                               southeastCorner: MSGeoposition(latitude:47.589908, longitude:-122.313251))
let scene = MSMapScene(boundingBox: seattle)
mapView.setScene(scene, with: .linear)

Objective-C

MSGeoboundingBox *seattle =
    [MSGeoboundingBox geoboundingBoxWithNorthwestCorner:[MSGeoposition geopositionWithLatitude:47.599025 longitude:-122.339901]
                                      southeastCorner:[MSGeoposition geopositionWithLatitude:47.589908 longitude:-122.313251]];
MSMapScene *scene = [MSMapScene sceneWithBoundingBox:seattle];
[self.mMap setScene:scene withAnimationKind:MSMapAnimationKindLinear];

See also MapScene