开发者

How can I use a RESTful JSONResult from my controller to populate Bing Maps Geocoding?

开发者 https://www.devze.com 2023-01-02 11:32 出处:网络
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.

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:" + 开发者_如何学JAVAlocation.Longitude;
        newShape.SetDescription(desc);
        newShape.SetTitle(bestPlace.Name);
        map.AddShape(newShape);
    }

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

</script>


Well damn.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号