First thing you have to do is to get key to work with Bing services. This can be done here - https://www.bingmapsportal.com/. Register your application and copy key.
I've build my solution based on this article. The code:
RefreshCoords = function()
{
var bingkey = "Paste your Key here";
var address = '';
if (crmForm.all.address1_line1.DataValue != null)
address += crmForm.all.address1_line1.DataValue;
if (crmForm.all.address1_line2.DataValue != null)
address += (address == '' ? '' : ' ') + crmForm.all.address1_line2.DataValue;
if (crmForm.all.address1_city.DataValue != null)
address += (address == '' ? '' : ' ') + crmForm.all.address1_city.DataValue;
if (crmForm.all.address1_stateorprovince.DataValue != null)
address += (address == '' ? '' : ' ') + crmForm.all.address1_stateorprovince.DataValue;
if (crmForm.all.address1_postalcode.DataValue != null)
address += (address == '' ? '' : ' ') + crmForm.all.address1_postalcode.DataValue;
var url = "http://dev.virtualearth.net/REST/v1/Locations?q=" + address + "&o=xml&key=" + bingkey;
try
{
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("GET", url, false);
xHReq.Send(null);
var resultXml =xHReq.responseXML;
var long = parseFloat(resultXml.selectSingleNode("//Response/ResourceSets/ResourceSet/Resources/Location/Point/Longitude").nodeTypedValue);
var lat = parseFloat(resultXml.selectSingleNode("//Response/ResourceSets/ResourceSet/Resources/Location/Point/Latitude").nodeTypedValue);
crmForm.all.address1_latitude.DataValue = lat;
crmForm.all.address1_longitude.DataValue = long;
crmForm.all.address1_latitude.ForceSubmit = true;
crmForm.all.address1_longitude.ForceSubmit = true;
}
catch(e){}
}
I am attempting to implement this solution and am receiving errors. Does this solution work for you exactly as is above?
ReplyDeleteHi.
ReplyDeleteThank you for response. Actually there was an error which is fixed now. Try to use this script. Feel free to left your comments here.
When do you execute this code?
ReplyDeleteHello, Jameson.
ReplyDeleteI use this code for example when address of contact was changed.