none
How to get the geocode for the Abbrevation Country or Region Name using bing Map Api ? RRS feed

  • Question

  •  Hi 

    I am using the bing map for the implementation of the feature to get the geocode based upon the abbrevation text code such as APAC for Asia Pacific, EMEA for Europe,Middle East, NA for North America & LA for Latin America.

    Could you please help and suggest how can we achieve this using bing map api code ?

    please find the attached code of mine . It does not result the expected output.

    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <meta charset="utf-8" />
        <script type='text/javascript'>
            var mapsearchManager;
            function GetMap() {
                map = new Microsoft.Maps.Map('#myMap', {});
                //Make a request to geocode New York, NY.
                geocodeQuery("APAC");
                geocodeQuery("NA");
                geocodeQuery("EMEA");
                geocodeQuery("LA");
            }
            function geocodeQuery(query) {
                //If search manager is not defined, load the search module.
                if (!searchManager) {
                    //Create an instance of the search manager and call the geocodeQuery function again.
                    Microsoft.Maps.loadModule('Microsoft.Maps.Search'function () {
                        debugger;
                        searchManager = new Microsoft.Maps.Search.SearchManager(map);
                        geocodeQuery(query);
                    });
                } else {
                    var searchRequest = {
                        where: query,
                        includeCountryIso2: true,
                        includeEntityTypes: [
                            'Address',
                            'Neighborhood',
                            'PopulatedPlace',
                            'Postcode1',
                            'AdminDivision1',
                            'AdminDivision2',
                            'CountryRegion',
                        ],
                        callback: function (r) {
                            //Add the first result to the map and zoom into it.
                            if (r && r.results && r.results.length > 0) {
                                var pin = new Microsoft.Maps.Pushpin(r.results[0].location);
                                map.entities.push(pin);
                                map.setView({ bounds: r.results[0].bestView });
                            }
                        },
                        errorCallback: function (e) {
                            //If there is an error, alert the user about it.
                            alert("No results found.");
                        }
                    };
                    debugger;
                    //Make the geocode request.
                    searchManager.geocode(searchRequest);
                }
            }
        </script>
        <script type='text/javascript'
            src='https://www.bing.com/api/maps/mapcontrol?callback=GetMap&key=[BING_MAP_API_KEY]'
            async defer></script>
    </head>
    <body>
        <div id="myMap" style="width:800px;height:600px;"></div>
    </body>
    </html>


    Friday, May 29, 2020 7:47 AM

All replies

  • Hi Sachin,

    We do not have continent polygons but do have country polygons.  The best UI to test these API values is our ISDK, https://www.bing.com/api/maps/sdk/mapcontrol/isdk/sdsloadboundaryfromsearch and the values like "Populated Place" are documented at https://docs.microsoft.com/en-us/bingmaps/spatial-data-services/ under Geodata API > Entity types.

    Sincerely,

    IoTGirl

    Friday, May 29, 2020 6:03 PM
    Owner
  • Hi,

    We have tried to implemented the same code but getting the incorrect plotting like Rep. of Korea is getting plot wrongly. Though I have specified the includeEntityType can you pleas help us.

    Please find the below code for your references : 

     
    var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {});
    //Load the Bing Spatial Data Services module
    Microsoft.Maps.loadModule(['Microsoft.Maps.SpatialDataService''Microsoft.Maps.Search'], function () {
        var searchManager = new Microsoft.Maps.Search.SearchManager(map);
        var geocodeRequest = {
            where: 'Rep. of Korea',
             includeEntityTypes: [
                'PopulatedPlace',
                'CountryRegion',
                'Neighborhood',
                'Address',
                'PopulatedPlace',
                'Postcode1',
                'AdminDivision1',
                'AdminDivision2',
                
            ],
            callback: function (geocodeResult) {
                debugger;
                if (geocodeResult && geocodeResult.results && geocodeResult.results.length > 0) {
                    map.setView({ bounds: geocodeResult.results[0].bestView });
                    var geoDataRequestOptions = {
                        entityType: 'PopulatedPlace',
                        getAllPolygons: true
                    };
                    //Use the GeoData API manager to get the boundary of New York City
                    Microsoft.Maps.SpatialDataService.GeoDataAPIManager.getBoundary(geocodeResult.results[0].locationgeoDataRequestOptionsmapfunction (data) {
                        if (data.results && data.results.length > 0) {
                            map.entities.push(data.results[0].Polygons);
                        }
                    }, nullfunction errCallback(networkStatusstatusMessage) {
                        console.log(networkStatus);
                        console.log(statusMessage);
                    });
                }
            },
        };
        searchManager.geocode(geocodeRequest);
    });
    Wednesday, June 3, 2020 12:01 PM