0

我知道这方面有一些主题,但我似乎在摸索着没有结果。我正在尝试使用控制器将 JSON 结果返回到我的 Bing Maps 函数。

这是我的控制器所拥有的(是的,它正确地返回了 JSON 数据。

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

然后在我的脚本中我有这个,但它不起作用。

<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>
4

1 回答 1

0

该死的。

原来我this.address在应该使用this.Address. 不敢相信我错过了。

于 2010-06-08T21:15:30.523 回答