views:

28

answers:

1

How to display Bing map dynamically in an ASP.NET website based on the address provided. I do not have latitude and longitude for the address so I have to pass address directly and display the map.

A: 

In the ASP.Net mark up page, I have a hidden field which contains address. Based on this address, bing map gets loaded using the script mentioned below. A pushpin is placed on the address for easy identification of the address.

var map = null;
var pinid = 0;

function GetMap() {

    map = new VEMap('theMap');
     map.LoadMap();
    map.SetZoomLevel(10);
    FindLoc(); 
}

function FindLoc() {
    try {
        map.Find("<b>Property Address:</b>",
                            document.getElementById('ctl00_head_HiddenField1').value,
                              null,
                              null,
                              1,
                              1,
                              true,
                              true,
                              true,
                              true,
                              ProcessResults);
    }
    catch (e) {
        alert(e.message);
    }
}

function ProcessResults(layer, results, places, hasmore) { CreatePin("Default", places[0].LatLong); }

function CreatePin(type, point) { if (point != 'Unavailable') { var pin = new VEShape(VEShapeType.Pushpin, point); pin.SetTitle('Property Address:');
pin.SetDescription(document.getElementById('ctl00_head_HiddenField1').value); map.AddShape(pin); } }

banupriya