Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get the latitude and longitude for a particular address using c# and Asp.NET
Please help me anybody using googlemap
Posted
Comments
Sandeep Mewara 13-May-11 13:00pm    
No effort.

Here is an example of how to do it :

C#
public void GetCoOrdinates(string street, string city, string state)
        {
            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));
        }


instead of a message box you can just write Response.Write() or similar for a web app.

Hope this helps
 
Share this answer
 
Comments
CPallini 3-Jun-11 6:28am    
[Carlo on behalf of the OP] Hi,

The following error was came. IF u know free service of this, please tell me

006We currently throttle, rate limit, requests to our free XML port to a maximum number of lookups per request source per day to ensure fair and equal access to our free services. If you need this limit raised for your non-for-profit entity contact us with this message: 122.169.155.234 . Otherwise you might want to look at our pay-per-use unthrottled port.
Wayne Gaylard 3-Jun-11 6:31am    
Hi, no the free service comes with limitations. If you want to use this service commercially then you need to pay them. They have a scheme where you can pay per use.
CPallini 3-Jun-11 6:35am    
That's not an error, it is a 'term of service' notice :rolleyes:
Mukund Thakker 20-Feb-13 4:22am    
The remote server returned an error: (503) Server Unavailable.
Try this: It worked for me...

C#
public List<string> GetCoOrdinates(string street, string city, string state)
        {
            try
            {
                List<string> lstCordinates = new List<string>();

                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;

                //Console.WriteLine(String.Format("Latitude: {0} Latitude: {1}", latitude, longitude));

                lstCordinates.Add(latitude);
                lstCordinates.Add(longitude);

                return lstCordinates;
            }
            catch (Exception ex)
            {
                throw ex;
            }            
        }</string></string></string>
 
Share this answer
 
v2
it showing below error
Data at the root level is invalid. Line 1, position 1.
 
Share this answer
 
Comments
niralirshah 10-Jun-13 5:47am    
I am also getting same error.. please help..

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