none
Plotting Multiple Addresses RRS feed

  • Question

  • I am trying to improve web performance so that I am not making 100 independent requests to BingMaps.  What is the best way to geocode multiple address so they can immediately be plotted on the map?  I have looked at Spacial and DataFlow, but am not sure if they are what I need.  My current attempt is below.

    Thanks!

    function map_PlotAddressList(addressList) {
        Microsoft.Maps.loadModule('Microsoft.Maps.Search', function () {
            _search = new Microsoft.Maps.Search.SearchManager(_map);
            var geocodeRequest = [];
            for (i = 0; i < addressList.length; i++) {
                geocodeRequest.push({ where: addressList[i].Address, count: 1, callback: map_Geocode_Callback, errorCallback: map_Error_Callback, userData: addressList[i] });            
            }
            _search.geocode(geocodeRequest);
        });
    }
    function map_Geocode_Callback(geocodeResult, userData) {
        try {
            var pOptions = { icon: userData.MapIcon, typeName: 'mapPin' };
            var pin = new Microsoft.Maps.Pushpin(geocodeResult.results[0].location, pOptions);
            pin.Title = userData.Title;
            pin.PropertyID = userData.PropertyID;
            pin.Description = "<a target='_blank' href='" + userData.PropertyURL + "'>" + userData.Description + "</a>";
            Microsoft.Maps.Events.addHandler(pin, 'click', map_ShowInfo);
            Microsoft.Maps.Events.addHandler(pin, 'mouseover', map_ShowInfo);
            Microsoft.Maps.Events.addHandler(pin, 'mouseout', map_HideInfo);
            Microsoft.Maps.Events.addHandler(_map, 'viewchange', map_HideInfo);
            _dataLayer.push(pin);
            _map.entities.push(pin);
        } catch (e) { }
    }


    Sunday, February 11, 2018 4:22 PM

Answers

  • A best practice with any mapping platform is to geocode any and all data you can ahead of time. This will drastically improve performance and reduce costs. Note that map sessions are only allowed to generate 50 non-billable transactions per session. If you geocode 100 addresses every time your map is used, it will generate an additional 50 billable transactions, thus making your application very expensive to run. Also, there is a limit to the number of requests your application can make to the Bing Maps servers for things like geocoding per second. Licensed enterprise accounts are allowed 50 queries per second and basic accounts are limited to 5 queries per second. As such, geocoding a list of a hundred addresses in a loop in a client app will likely hit these limits fairly quickly which will results in some geocode requests being blocked. 

    Bing Maps allows you to geocode your data ahead of time and to store the geocode results in your data for use with Bing Maps in the future. This is what nearly every mapping application does. To geocode your data ahead of time you could use the batch geocoding service in the spatial data services, or you could format your data as a simple 2d table that aligns with the data source requirements of the spatial data services and upload it to as a data source either through the Bing Maps portal (easy) or via the developer API's. This will batch geocode your data for you and expose it as a spatial REST service so you can do things like find nearby locations or find locations along a route. Alternatively you could use the REST Location API and geocode each address individually, similar to what your code is doing now, but have it store the resulting coordinates in your data, were ever that is hosted (database, flat file such as GeoJSON or KML). 

    If you geocode your data ahead of time there would be no need to do any geocoding within your app and thus loading the map and displaying 100 locations would be very fast and much faster than geocoding the data on the fly. 

    Once your data is geocoded and it is being loaded into the dataLayer, instead of added events to the individual pushpins, add them to the dataLayer once. Doing this right after creating your layer likely would be easiest. Also, add your map event right after loading the map, not in a callback, otherwise you will end up adding the event several times to the map which would cause issues. 


    [Blog] [twitter] [LinkedIn]

    Monday, February 12, 2018 5:40 PM