Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#4.0
I want to get the latitude and longitude for a particular address using c# and Asp.NET
Please help me anybody using googlemap
Posted 13-May-11 2:06am
Jameel VM14.5K
Comments
S Mewara at 13-May-11 13:00pm
   
No effort.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Here is an example of how to do it :
 
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
  Permalink  
Comments
CPallini at 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 at 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 at 3-Jun-11 6:35am
   
That's not an error, it is a 'term of service' notice :rolleyes:
Mukund Thakker at 20-Feb-13 4:22am
   
The remote server returned an error: (503) Server Unavailable.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Try this: It worked for me...
 
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>
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

it showing below error
Data at the root level is invalid. Line 1, position 1.
  Permalink  
Comments
niralirshah at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 7,373
1 OriginalGriff 5,571
2 Peter Leow 4,097
3 CHill60 2,858
4 Mika Wendelius 2,850


Advertise | Privacy | Mobile
Web03 | 2.8.150224.1 | Last Updated 27 Nov 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100