Click here to Skip to main content
15,887,962 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am working with Bing Maps API. What I am trying to accomplish is to have an infobox popup onclick with the zipcode location of the location clicked. The code below is what I have so far but it is not working. I either get the "object Object" error or "object undefined" error or like with the current code, the infobox doesnt come up at all.

What I have tried:

function loadMapScenario() {
    var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {
        credentials: '...',
        disableStreetside: true,
        mapTypeId: Microsoft.Maps.MapTypeId.road,
        enableSearchLogo: false,
        showMapTypeSelector: false,
        showScalebar: false
                });
                Microsoft.Maps.Events.addHandler(map, 'click', function (e) {
                    if (e.targetType == 'map') {
                        var point = new Microsoft.Maps.Point(e.getX(), e.getY());
                        var loc = e.target.tryPixelToLocation(point);
                        var location = new Microsoft.Maps.Location(loc.latitude, loc.longitude);
                        Microsoft.Maps.loadModule('Microsoft.Maps.Search', function () {
                            var searchManager = new Microsoft.Maps.Search.SearchManager(map);
                            var reverseGeocodeRequestOptions = {
                                location,
                                callback: function (answer, userData) {
                                    var zipcode = answer.address.postalCode;
                                }
                            }
                            searchManager.reverseGeocode(reverseGeocodeRequestOptions);
                            var infobox = new Microsoft.Maps.Infobox(location, { title: 'Map Center',description: '' + zipcode});
                            infobox.setMap(map);
                        });
                    }
                });
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900