Get the Latitude and longitude by passing address
Pass the parameters in this function
public string getlatitude(string
data)
{
string
LatLng = null;
//string
latlng = "17.426895,78.452497";
string
url = "http://maps.google.com/maps/api/geocode/xml?address="
+ data + "&sensor=false";
WebRequest request =
WebRequest.Create(url);
//request.Timeout
= 10000;
using
(HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using
(Stream dataStream =
response.GetResponseStream())
{
using
(StreamReader reader = new StreamReader(dataStream))
{
//context.Response.Write(reader.ReadToEnd());
string st = reader.ReadToEnd().Trim();
if
(st != "")
{
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(st);
XmlNodeList lat =
xdoc.GetElementsByTagName("lat");
XmlNodeList lng =
xdoc.GetElementsByTagName("lng");
if (lat.Count > 0)
{
string Latitude = lat[0].InnerText;
string Longitude = lng[0].InnerText;
LatLng =
Latitude + "," + Longitude;
//context.Response.Write(place);
}
}
}
return
LatLng;
}
}
}use above function like
textbox1.text=getlatitude("hyderabad");
Actually the above url returns xml form data
Get the Address by passing latitude and longitude
Pass the parameters in this function
public string GetAddress(string
data)
{
string
FullAdd = null;
//string
latlng = "17.426895,78.452497";
string
url = "http://maps.google.com/maps/api/geocode/xml?latlng="
+ data + "&sensor=false";
WebRequest request =
WebRequest.Create(url);
//request.Timeout
= 10000;
using
(HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using
(Stream dataStream =
response.GetResponseStream())
{
using
(StreamReader reader = new StreamReader(dataStream))
{
//context.Response.Write(reader.ReadToEnd());
string st = reader.ReadToEnd().Trim();
if (st != "")
{
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(st);
XmlNodeList lat =
xdoc.GetElementsByTagName("formatted_address");
//XmlNodeList lng =
xdoc.GetElementsByTagName("lng");
if (lat.Count > 0)
{
string address = lat[0].InnerText;
FullAdd =
address;
//context.Response.Write(place);
}
}
}
return
FullAdd;
}
}
}
textbox1.text=GetAddress("hyderabad");
For any
clarifications or queries please don’t hesitate to call or Email
Phone :- + 91-9492179390
No comments:
Post a Comment