ASP.NET MVC Consume JSONResult in Bing Maps API

Posted by rockinthesixstring on Stack Overflow See other posts from Stack Overflow or by rockinthesixstring
Published on 2010-06-08T04:01:16Z Indexed on 2010/06/08 4:12 UTC
Read the original article Hit count: 529

I know there are a few topics on this, but I seem to be fumbling my way through with no results. I'm trying to use a controller to return JSON results to my Bin Maps functions.

Here's what I have for my controller (yes it is properly returning JSON data.

Function Regions() As JsonResult
    Dim rj As New List(Of RtnJson)()
    rj.Add(New RtnJson("135 Bow Meadows Drive, Cochrane, Alberta", "desc", "title"))
    rj.Add(New RtnJson("12 Bowridge Dr NW, Calgary, Alberta, Canada", "desc2", "title2"))

    Return Json(rj, JsonRequestBehavior.AllowGet)
End Function

Then in my script I have this, but it's not working.

<script type="text/javascript">
    var map = null;
    var centerLat = 51.045 ;    
    var centerLon = -114.05722;

    var json_object = $.getJSON("<%: Url.Action("Regions", "Events")%>");


    function LoadMap() {
        map = new VEMap('bingMap');
        map.LoadMap(new VELatLong(centerLat, centerLon), 10);
            $.each(json_object, function () {
            alert(this.address); //this alert is returning "address is undefined"
                StartGeocoding(this.address, 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>

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about rest