I have been trying to put a Bing map into my Lightswitch visual studio project and found some code on the internet which I have adapted to my own data. However, I can get the map to load up but it doesn't seem to be taking my data and just shows a random point in the middle of the ocean as opposed to the locations I am inputting!
This is the code I have found and adapted:
function rebindMap(element, contentItem) {
// Verify that we aren't updating the map continuously due to multiple bound values changing.
var now = new Date();
if (now.getTime() - mapLastUpdated.getTime() > 15) {
setTimeout(function () {
updateMap(element, contentItem);
mapLastUpdated = new Date();
}, 20);
}
};
function updateMap(element, contentItem) {
var mapDiv = $("#appointmentMap");
// If we've previously created the map, make sure to clean up the div that contained it;
// otherwise, the Bing map control fails to create properly.
if (mapDiv.length > 0) {
$(mapDiv).remove();
}
mapDiv = $("<div id='appointmentMap' class='msls-hauto msls-vauto' ></div>");
$(mapDiv).appendTo($(element));
mapControl = mapDiv.lightswitchBingMapsControl({
country: contentItem.value.Spatial_Data,
state: contentItem.value.State_Province,
postalcode: contentItem.value.Postal_Code,
address: contentItem.value.Address,
city: contentItem.value.City,
latitude: contentItem.value.Latitude,
longitude: contentItem.value.Longitude,
mapTypeId: Microsoft.Maps.MapTypeId.road,
height: "400"
});
};
myapp.View_Retail.Site_Name1_render = function (element, contentItem) {
// Write code here.
updateMap(element, contentItem);
mapLastUpdated = new Date();
contentItem.dataBind("value.country", function () { rebindMap(element, contentItem); });
contentItem.dataBind("value.state", function () { rebindMap(element, contentItem); });
contentItem.dataBind("value.postalcode", function () { rebindMap(element, contentItem); });
contentItem.dataBind("value.address", function () { rebindMap(element, contentItem); });
contentItem.dataBind("value.city", function () { rebindMap(element, contentItem); });
contentItem.dataBind("value.latitude", function () { rebindMap(element, contentItem); });
contentItem.dataBind("value.longitude", function () { rebindMap(element, contentItem); });
};
I got the code from the Microsoft website: http://technet.microsoft.com/en-ca/jj674624(v=vs.71).aspx
I don't understand what I am missing! I'm not very experienced in javascript so any help would be greatly appreciated :)