views:

279

answers:

0

I've been banging my head against my desk with this problem. I've got the below code working properly, however what I WANT to be able to do is add my custom Title to the newShape.SetTitle(title) and my custom Desc to the newShape.SetDescription(desc)

I have tried adding the "title" and the "description" to the GeoCodeCallback function like this function GeocodeCallback(shapeLayer, findResults, places, moreResults, errorMsg, title, desc) but it just makes it so that all of the other parameters are broken.

Can anyone lend a helping hand on this?

<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"&gt;&lt;/script&gt;
<script type="text/javascript">
    var map = null;

    var json_object = [
        { "addr": "445 Harper St, Prince George, BC, Canada", "title": "My Last Home", "desc": "Here is where I used to live" },
        { "addr": "12 Bowridge Dr NW, Calgary, Alberta, Canada", "title": "RockPointe Bowridge", "desc": "Here is a RPC site" }
    ];


    function LoadMap() {
        map = new VEMap('bingMap');
        map.LoadMap(new VELatLong(51.045, -114.05722), 10);
            $.each(json_object, function () {
                StartGeocoding(this.addr, this.title, this.desc);
            });
    }

    function StartGeocoding(address, title, desc) {
        map.Find(null,    // what
          address, // where
          null,    // VEFindType (always VEFindType.Businesses)
          null,    // VEShapeLayer (base by default)
          null,    // start index for results (0 by default)
          null,    // max number of results (default is 10)
          null,    // show results? (default is true)
          null,    // create pushpin for what results? (ignored since what is null)
          true,    // use default disambiguation? (default is true)
          false,    // set best map view? (default is true)
          GeocodeCallback);  // call back function
    }

    function GeocodeCallback(shapeLayer, findResults, places, moreResults, errorMsg) {

        var bestPlace = places[0];

        // Add pushpin to the *best* place
        var location = bestPlace.LatLong;

        var newShape = new VEShape(VEShapeType.Pushpin, location);

        var desc = "Latitude: " + location.Latitude + "<br>Longitude:" + location.Longitude;
        newShape.SetDescription(desc);
        newShape.SetTitle(bestPlace.Name);
        map.AddShape(newShape);
    }

    $(document).ready(function () {
        LoadMap();
    });

</script>