Basic Intersection Search Example

This example shows how to make a simple intersection query against a data source using the map bounds. As you pan and zoom the map a new query is made to load in new data for the map bounds.

<!DOCTYPE html>
    <meta charset="utf-8" />
	<script type='text/javascript'>
    var map;

    //Query URL to the Fourth Coffe Shop data source
    var sdsDataSourceUrl = '';

    function GetMap() {
        map = new Microsoft.Maps.Map('#myMap', {});

        //Load the Bing Spatial Data Services module.
        Microsoft.Maps.loadModule('Microsoft.Maps.SpatialDataService', function () {
            //Add an event handler for when the map moves.
            Microsoft.Maps.Events.addHandler(map, 'viewchangeend', getLocationsInView);

            //Trigger an initial search.

    function getLocationsInView() {
        //Remove any existing data from the map.

        //Create a query to get data that intrsects the bounds of the map.
        var queryOptions = {
            queryUrl: sdsDataSourceUrl,
            top: 250,
            spatialFilter: {
                spatialFilterType: 'intersects',
                intersects: map.getBounds()

        //Process the query., map, function (data) {
            //Add results to the map.
    <script type='text/javascript' src='[YOUR_BING_MAPS_KEY]' async defer></script>
    <div id="myMap" style="position:relative;width:600px;height:400px;"></div>

When loaded this code will retrieve results from the Fourth Coffee Shop sample data source as you pan and zoom the map that fall within the map bounds.