Andrew Woodard
Andrew Woodard

Reputation: 545

Address to longitude and latitude conversions issues

I am trying to use following code to return a longitude and latitude based on an address from Microsoft dynamics CRM 2011 Online. The address is picking up ok but the code below is not working. Can anyone please help me on figuring out a reason why.

try
{
    var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
    xHReq.Open("GET", "http://maps.google.com/maps/api/geocode/xml?sensor=false&address=" + address, false);
    xHReq.Send(null);

    var resultXml =xHReq.responseXML;
alert(resultXml);
    var addressComponents=resultXml.selectNodes("//GeocodeResponse/result/geometry/location");
    if (addressComponents != null && addressComponents.length > 0) 
    {
        var long = parseFloat(resultXml.selectSingleNode("//GeocodeResponse/result/geometry/location/lng").nodeTypedValue);
        var lat = parseFloat(resultXml.selectSingleNode("//GeocodeResponse/result/geometry/location/lat").nodeTypedValue);

        crmForm.all.address1_latitude.DataValue = lat;
        crmForm.all.address1_longitude.DataValue = long;
        alert(lat);

crmForm.all.address1_latitude.ForceSubmit = true;
        crmForm.all.address1_longitude.ForceSubmit = true;
        }

}

I am getting the following error message: Permission Denied.

I'm starting to wonder if I am having issues due to the site being https://.

Has anyone else run into the same error.

Upvotes: 0

Views: 682

Answers (2)

M Hasan Sunny
M Hasan Sunny

Reputation: 29

Please go the url, http://rubenb.home.xs4all.nl/latitudelongitude/latlon.html

Convert an address to longitude and latitude by just typing in the address. You can type any address in the world as long as you use following format: street, city, country or street, city, state. Even you can find the longitude and latitude belonging to a house number. You can copy and paste the longitude or latitude to your GPS or to any program which is using long/latitude, like "poi editor" or "IGo poi explorer". This site is very usefull if you want to create a Poi file for your navigation tool.

This site is using the geocoding scripts from Google. Geocoding is the process of estimating a latitude and longitude for a given location.

Upvotes: 0

Andrew Leach
Andrew Leach

Reputation: 12983

You can't use XMLHttp to reach data in a domain if your own code is not already in that domain (cross-domain restriction). Because your code is not served from google.com, you cannot reach data in that domain.

For Javascript, use the geocoding service in the Javascript API as Mano has commented. Essentially, that uses JSON and is not constrained in that way.

Upvotes: 2

Related Questions