Click here to Skip to main content
15,893,190 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I am trying to converting an address to lat and lng.
This is what I used but I'm getting this error

C#
public void GetCoOrdinates()
        {
            string serviceUri = string.Format("http://rpc.geocoder.us/service/rest?address={0},{1},{2}", street, city, state);
            XmlDocument serviceXmlDoc = new XmlDocument();
            serviceXmlDoc.Load(serviceUri);
            XmlNamespaceManager geoCoderManager = new XmlNamespaceManager(serviceXmlDoc.NameTable);
            geoCoderManager.AddNamespace("geoCoderService", @"http://www.w3.org/2003/01/geo/wgs84_pos#");
            string longitude = serviceXmlDoc.DocumentElement.SelectSingleNode(@"//geoCoderService:long", geoCoderManager).InnerText;
            string latitude = serviceXmlDoc.DocumentElement.SelectSingleNode(@"//geoCoderService:lat", geoCoderManager).InnerText;
            MessageBox.Show(String.Format("Latitude: {0} Latitude: {1}", latitude, longitude));
        }

ERROR: Data at the root level is invalid. Line 1, position 1
Posted
Updated 14-Mar-12 3:26am
v2
Comments
BobJanova 14-Mar-12 9:30am    
Are you sure you're submitting the service request in the right format? Check the service provider's documentation and examples.

1 solution

You're goingo to have to contact GeoCoder on this one. We have no idea what their service requires.

Also, you do know that you're never going to get a completely accurate location for any given IP, correct?? You could get a result that's off by upwards of 100 miles.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900