これについていくつかのトピックがあることは知っていますが、結果が得られずに自分の道をいじくり回しているようです。コントローラを使用してJSONの結果をBingMaps関数に返そうとしています。
これが私のコントローラー用のものです(はい、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>