By 01/01/2014 12 Comments

How to get Longitude and Latitude by Address in C#

What is Longitude and  Latitude ?

  • It is a geographic coordinate
  • It  specifies the east west position on the surface of earth
  • It is an angular measurement which is called degrees
  • It’s measurement denoted by lambda

Read about following Longitude and Latitude example

  • Create a class with LatLong name
  • Inside class create a public static method GetLongitudeAndLatitude which will take two parameters named address:string and sensor:string. It must return string array.
  • Following is whole code of class
class LatLong

{

public static string[] GetLongitudeAndLatitude(string address, string sensor)

{

string[] LatLongArray = new string[2]; // declare an array with 2 length

string urlAddress = "http://maps.googleapis.com/maps/api/geocode/xml?address=" + HttpUtility.UrlEncode(address) + "&sensor=" + sensor; // assign google map API into string urlAddress

//string returnValue = "";

try

{

XmlDocument objXmlDocument = new XmlDocument(); // create an object

objXmlDocument.Load(urlAddress); // pass a google map API string from the load method as a parameter

XmlNodeList objXmlNodeList = objXmlDocument.SelectNodes("/GeocodeResponse/result/geometry/location"); // set node list

foreach (XmlNode objXmlNode in objXmlNodeList)

{

// GET LATITUDE

LatLongArray[0] = objXmlNode.ChildNodes.Item(0).InnerText;

// GET LONGITUDE 

LatLongArray[1] = objXmlNode.ChildNodes.Item(1).InnerText;

}

}

catch

{

// Process an error action here if needed

}

return LatLongArray;

}

}
  • Now call this method where you need and it will take two parameters  One is address and other is sensor
  • Code for calling method
string[] logLatarray = LatLong.GetLongitudeAndLatitude("address", "false");

string latitude=logLatarray[0];

string longitude=logLatarray[1];

 







Posted in: C#.NET

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .