Michael Witt
Michael Witt

Reputation: 1712

bing maps upgrading from v7 to v8 error with userMapView

I'm upgrading a project from using the bing maps v7 ajax api to using the v8 api. I've run into a problem where I'm getting back a message saying that "The waypoint you entered cannot be found." So I backed up and modified a sample screen to do what I'm doing and it works fine. So I've narrowed it down (with fiddler) to the REST calls that are made for each waypoint getting an error saying the userMapView is out of range in the first case but works fine in the second. I'm not really sure why this might be different in the sample code versus my actual app. Here are the two URLs. The first is the one that fails:

https://dev.virtualearth.net/REST/v1/Locations/?q=Cincinnati%2C%20OH&o=json&culture=en-US&jsonp=Microsoft.Maps.NetworkCallbacks.f5de44&key=MY_BING_MAPS_KEY&maxResults=5&userMapView=39.18820190429691,-180,39.18820190429691,-180&inclnb=0&incl=

https://dev.virtualearth.net/REST/v1/Locations/?q=cincinnati%2C%20oh&o=json&culture=en-US&jsonp=Microsoft.Maps.NetworkCallbacks.f66617&key=MY_BING_MAPS_KEY&maxResults=5&userMapView=39.02836016935031,-85.12275695800781,39.34768093312603,-85.12275695800781&inclnb=0&incl=

If I replace the userMapView parameter of the first URL with those of the second, the first URL works too. It seems obvious that the "-180" degree part is incorrect, but I don't know how it is getting there.

BTW, both of these URLs were generated using my dev key.

Thanks for any help!

EDIT: Here's the bulk of the code that runs into trouble. Prior to this I've new'd the Map. This code is the callback from the loadModule of the Directions module. The code is a little convoluted beyond that though as I'm plugging in origins and destinations from the form. Also note, not that it makes much difference, that userAddress is passed into this function as true.

function createDrivingRoute(useAddress) {
    directionsManager = new Microsoft.Maps.Directions.DirectionsManager(bmap);
    locs = [];
    var fromWayPoint;
    fromWayPoint = new Microsoft.Maps.Directions.Waypoint({ address: fromAddressSearch });
    locs.push(fromWayPoint);
    directionsManager.addWaypoint(fromWayPoint);
    if (toLocationArray != null) {
        if (toLocationArray.length == 1) {
            if (toLocationArray[0] == false) {
                toLocationArray = [];
            }

        }
    }

    if (useAddress) {
        if (toLocationArray != null) {
            for (i = 0; i < toLocationArray.length; i++) {
                //var toWayPointLoc = new Microsoft.Maps.Directions.Waypoint({ location: toLocationArray[i] });
                var toWayPointLoc = new Microsoft.Maps.Directions.Waypoint({ address: toLocationArray[i] });
                locs.push(toWayPointLoc);
                directionsManager.addWaypoint(toWayPointLoc);
            }
            for (i = 0; i < toAddressArray.length; i++) {
                var toWayPoint = new Microsoft.Maps.Directions.Waypoint({ address: toAddressArray[i] });
                locs.push(toWayPoint);
                directionsManager.addWaypoint(toWayPoint);
            }
        } else {
            for (i = 0; i < toAddressArray.length; i++) {
                var toWayPoint = new Microsoft.Maps.Directions.Waypoint({ address: toAddressArray[i] });
                locs.push(toWayPoint);
                directionsManager.addWaypoint(toWayPoint);
            }
       }
    } else {
            if (toLocationArray != null) {
                for (i = 0; i < toLocationArray.length; i++) {
                    //var toWayPointLoc = new Microsoft.Maps.Directions.Waypoint({ location: toLocationArray[i] });
                    var toWayPointLoc = new Microsoft.Maps.Directions.Waypoint({ address: toLocationArray[i] });
                    locs.push(toWayPointLoc);
                    directionsManager.addWaypoint(toWayPointLoc);
                }
            }
            for (i = 0; i < toAddressArray.length; i++) {
                var toWayPoint = new Microsoft.Maps.Directions.Waypoint({ address: toAddressArray[i] });
                locs.push(toWayPoint);
                directionsManager.addWaypoint(toWayPoint);
            }
        }


    if ($get("<%= chkReturnOrigin.ClientID %>").checked) {
        var returnWayPoint = new Microsoft.Maps.Directions.Waypoint({ address: fromAddressSearch });
        directionsManager.addWaypoint(fromWayPoint);
    }


    // Set the element in which the itinerary will be rendered
    directionsManager.setRenderOptions({ itineraryContainer: '#directions' });

    // Specify a handler for when the directions are calculated
    if (directionsUpdatedEventObj) {
        Microsoft.Maps.Events.removeHandler(directionsUpdatedEventObj);
        directionsUpdatedEventObj = null;
    }
    directionsUpdatedEventObj = Microsoft.Maps.Events.addHandler(directionsManager, 'directionsUpdated', onDirectionsDisplayedEvent);

    if (directionsErrorEventObj) {
        Microsoft.Maps.Events.removeHandler(directionsErrorEventObj);
        directionsErrorEventObj = null;
    }
    directionsErrorEventObj = Microsoft.Maps.Events.addHandler(directionsManager, 'directionsError', onDirectionsErrorEvent);

    loadedRoute = null;
    loadedSteps = [];
    directionsManager.calculateDirections();
    var destAddress = $get("<%= DestAddressList.ClientID %>").value;
    if (destAddress == null || destAddress == "") {
        document.getElementById("DistTotal").innerHTML = '';
    }
}

Upvotes: 1

Views: 564

Answers (1)

rbrundritt
rbrundritt

Reputation: 18023

Haven't seen this issue before, very odd. Take a look at your code, if you are using the Search module to do the geocoding, don't set the bounds option and see if it that corrects the issue. The bounds property is used to set the userMapView property of the REST request. If that works, then there is likely an issue with the LocationRect object being passed in, or how the search module uses it. I'll take a look into the source code to see if there is a bug that might be causing this.

Update 1: Now that I see your edit and see that you are using the directions manager I'm able to see that the userMapView is automatically added from the map. Not sure why it would be adding such incorrect values though. It looks like they are adding the same coordinate twice rather than adding the northwest and southeast coordinates. Will see if I can verify this by digging through the code.

Update 2: I've found the bug in the code. I have logged this with the development team so that they can resolve it the next time they touch the code for the search manager. The issue is that the west value is being added to the userMapView request twice, but not adding east value.

Update 3: Good news, this bug is now resolved in the experimental branch of Bing Maps. You can try this out by adding "&branch=experimental" to the map script URL. This will be added to the release branch in the next regular update planned for February.

Upvotes: 2

Related Questions