0
我想將bing地圖集成到網頁上,並且還想將動態引腳和描述框添加到地圖中。所以我添加了這個JS腳本。使用json將引腳和描述框放在bing地圖上
var map = null;
var pinInfoBox; //the pop up info box
var infoboxLayer = new Microsoft.Maps.EntityCollection();
var pinLayer = new Microsoft.Maps.EntityCollection();
function getMap()
{
map = new Microsoft.Maps.Map(document.getElementById('myMap'), {credentials: 'AlKxWcYscx4MaEZJeSsswwq2ZZ6U8QO283c0CCUL1opU-KJFxkA3C6qComzd5osp'});
/* Ajax call to get pins */
$.ajax({
type: 'POST',
url: 'api/getproperties.php',
dataType: "json",
data: {},
success: function (response)
{
var pins = $.parseJSON(response);
$.each(pins, function(pin)
{
var latLon = new Microsoft.Maps.Location(pin.Latitude,pin.Longitude);
var newpin = new Microsoft.Maps.Pushpin(latLon);
newpin.Title = pin.name;
newpin.Description = "description here";
pinLayer.push(newpin);
Microsoft.Maps.Events.addHandler(newpin, 'click', displayInfobox);
map.entities.push(pinLayer);
map.entities.push(infoboxLayer);
});
}
});
/* end ajax call for property pins*/
}
function displayInfobox(e)
{
pinInfobox.setOptions({title: e.target.name, description: "description here", visible:true, offset: new Microsoft.Maps.Point(0,25)});
pinInfobox.setLocation(e.target.getLocation());
}
function hideInfobox(e)
{
pinInfobox.setOptions({ visible: false });
}
Ajax調用是成功的,這是我的Json我Ajax調用後得到。地圖顯示正常,但不添加引腳。這裏可能有什麼問題?請提出解決方案。
[{"loc_id":"L0002","Latitude":"53.136886","Longitude":"-7.689056","name":"demo"}
,{"loc_id":"L0004","Latitude":"-33.932079","Longitude":"18.428093","name":"demo1"}...more data]