none
Geocoding migration from V6.2 to V8

    Question

  • Dear Sir:

    I am doing migration from V6.2 to V8

    The V6.2 code is as described below:

    ==============================================================================

    // Two Java session Arraylist that contains the name of the location and coordinates of the location

    // mapList contains list of location coordinates (Latitude and Logitude)

    // facilityList contains the name of the location

    var mapList = <%=new JavaScriptObjectConverter(result).toString()%>;
    var facilityList = <%=new JavaScriptObjectConverter(facilityName).toString()%>;

    // Loop through mapList using jQuery code

    $.each(mapList, function(index, value){
       try {

            map.Find(null, value, null, null, null, null, true, true, null, true, GetCoordinates);

            var myShapeLayer = new VEShapeLayer();
            map.AddShapeLayer(myShapeLayer);
            map.SetMapStyle(VEMapStyle.Hybrid);

       } catch (err) {}

    });

    function GetCoordinates(layer, resultsArray, places, hasMore, veErrorMessage)
    {
                findPlaceResults = places[0].LatLong;
                var latitude = findPlaceResults.Latitude;
                facilityAddress = places[0].Name;
                if (latitude > 0) {
                    emptyArray.push(findPlaceResults);
                    var myShape = new VEShape(VEShapeType.Pushpin, findPlaceResults);
                    myShape.SetDescription(facilityAddress);
                    map.SetMapView(emptyArray);
                    map.AddShape(myShape);
                }            
    }

    ====================================================================

    I tried to follow the migration guide to do the coding. However, because lack of detail I do not quite know how to do the conversion of geocoding from V6.2 to V8.

    Following are the code code I comes up, but, it lacks the major part related to geocoding conversion:

    ===========================================================================

    // Two Java session Arraylist that contains the name of the location and coordinates of the location

    // mapList contains list of location coordinates (Latitude and Logitude)

    // facilityList contains the name of the location

    var mapList = <%=new JavaScriptObjectConverter(result).toString()%>;
    var facilityList = <%=new JavaScriptObjectConverter(facilityName).toString()%>;

    // Loop through mapList using jQuery code

    $.each(mapList, function(index, value){

        Microsoft.Maps.loadModule('Microsoft.Maps.Search', { callback: searchModuleLoaded });
    });    

     function searchModuleLoaded() {
            if (!searchManager) {
                 searchManager = new Microsoft.Maps.Search.SearchManager(map);
            }
              
             var geocodeRequest = { where: address,
                                                     callback: GeocodeSuccessCallback,
                                                     errorCallback:GeocodeErrorCallback };
                                     
              searchManager.geocode(geocodeRequest);
              
              var myShapeLayer = new Microsoft.Maps.Layer();
              map.layers.insert(myShapeLayer);
              map.SetView(ViewOptions.mapTypeId.Hybrid);   // Do not know if there is Hybrid option for V8 or not
          }

          function GeocodeCallback(results, userData) {
             // Do NOT KNOW HOW TO CODE THIS PART

          }

    ================================================================================

    Can any body tell me how to code function GeocodeCallback(results, userData) ? or point me to the suitable reference or tutorial so that I can convert the original V6.2 to V8 Bing maps implementation?

    Thanks.

    Tuesday, November 27, 2018 2:53 PM

All replies

  • Hi John,

    Are you leveraging the migration guide at https://social.technet.microsoft.com/wiki/contents/articles/34568.bing-maps-v6-3-to-v8-migration-guide.aspx?

    From Section 4.3:

    When using v8, geocoding can be accomplished using the Search module Jump. Being a module you can delay the loading of this functionality until it is needed by the application. This helps improve page load performance. You can load the search module using the following code. 

    Microsoft.Maps.loadModule('Microsoft.Maps.Search', { callback: searchModuleLoaded });

    Once the module is loaded you can use the SearchManager class Jump to perform a geocode request. Here is an example of a basic implementation used to geocode an address and returns the results to a callback function in v8: 

    function GeocodeAddress(address) {
        var searchManager = new Microsoft.Maps.Search.SearchManager(map);
        searchManager.geocode({ where: address, callback: GeocodeCallback });
    }
     
    function GeocodeCallback(results, userData) {
        // Do something with the results
    }

    Here you will parse the "result" set for your data.  You could try something like this...

    functiongeocodeCallback(response, userData) {

        if(response &&

            response.results &&

            response.results.length > 0) {

            varr = response.results[0];

            varl = newMicrosoft.Maps.Location(r.location.latitude, r.location.longitude);

     

            //Display result on map       

            varp = newMicrosoft.Maps.Pushpin(l);

            map.entities.push(p);

    }

    Tuesday, November 27, 2018 5:37 PM
    Owner