none
Microsoft.Maps.AutosuggestManager not returning bestView? RRS feed

  • Question

  • I'm migrating an application from Bing Maps V7 to V8 and I'm having an issue with the AutoSuggest. What I had been doing is when a user makes a selection in the AutoSuggest then the map would center on the location using the bestView attribute returned in the suggestion result and add a pushpin. This worked in V7.

    The pushpin does get added correctly in V8 but the map is not being centred. When I checked in the debugger the suggestion result was missing the bestView attribute. When I go the documentation for the SuggestionResult Object bestView is an attribute that should be returned

    The link I'm using for Bing Maps is https://www.bing.com/api/maps/mapcontrol?callback=loadMap

    The code I'm using is 

    var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {
        credentials: bingMapCredentials,
        showDashboard: false
    });
    
    Microsoft.Maps.loadModule('Microsoft.Maps.AutoSuggest', function () {
        var options = {
            maxResults: 4,
            map: map
        };
        var manager = new Microsoft.Maps.AutosuggestManager(options);
        manager.attachAutosuggest('#txtSearch', '#searchBoxContainer', selectedSuggestion);
    });
    
    function selectedSuggestion(suggestionResult) {
        map.setView({ bounds: suggestionResult.bestView });
        newAddPinToMap(suggestionResult.formattedSuggestion, suggestionResult.location);
    }

    Is there a way to get the bestView attribute for suggestionResult? Is this a bug that will be fixed soon or should I be looking for a different value?

    Thursday, May 11, 2017 10:39 AM

Answers

  • yes, I believe we found the issue in a different post. Basically, for some reason, some culture settings are not getting a bounding box. The team is looking into this. To test, add the following to the map script tag "&setMkt=en-US&setLang=en-US". This will set it to US English and should work. 

    [Blog] [twitter] [LinkedIn]

    Monday, May 15, 2017 8:46 PM
  • I've tested these and all of them return a bestView and center the map over the result. Although it is zoomed out a decent amount.

    [Blog] [twitter] [LinkedIn]

    Monday, May 15, 2017 3:57 PM

All replies

  • What value are you passing into the suggestion box. 

    [Blog] [twitter] [LinkedIn]

    Saturday, May 13, 2017 5:48 PM
  • The values I'm using most often are

    • Ho Chi Minh City, Ho Chi Minh City, Vietnam
    • Hanoi, Thành Phố Hà Nội, Vietnam
    • Đà Nang, Da Nang City, Vietnam

    bestView is being returned as undefined for all of them.

    Monday, May 15, 2017 8:02 AM
  • I've tested these and all of them return a bestView and center the map over the result. Although it is zoomed out a decent amount.

    [Blog] [twitter] [LinkedIn]

    Monday, May 15, 2017 3:57 PM
  • OK. I checked the application using Visual Studio to debug the JavaScript and it is still coming back as undefined for me.

    I had set the bounds of the map to focus on Vietnam but even removing these did not change the value of bestView. It does not scroll and zoom when I make a selection from the drop down

    Monday, May 15, 2017 4:27 PM
  • yes, I believe we found the issue in a different post. Basically, for some reason, some culture settings are not getting a bounding box. The team is looking into this. To test, add the following to the map script tag "&setMkt=en-US&setLang=en-US". This will set it to US English and should work. 

    [Blog] [twitter] [LinkedIn]

    Monday, May 15, 2017 8:46 PM
  • Thanks Ricky. That did work for me.
    Tuesday, May 16, 2017 9:01 AM