views:

27

answers:

1

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 Bing 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 path = "<%: Url.Action("GetRegions", "Regions")%>";


    function LoadMap() {
        map = new VEMap('bingMap');
        map.LoadMap(new VELatLong(centerLat, centerLon), 10);
            $.getJSON(path, function(json){
                $.each(json, function(){  
                    alert(this.address);  // the alert message is "undefined"
                    StartGeocoding(this.address, this.title, this.description);
                });
            });
    }

    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>
A: 

Well damn.

Turns out that I was using this.address when I should have been using this.Address. Can't believe I missed that.

rockinthesixstring
My problem was that I created private variables like `_address` and used ReSharper to create my Properties... ReSharper automatically capitalized the properties.
rockinthesixstring