Sunday, February 24, 2013

Get the latitude and longitude by passing the MCCC,MNC,CELLID


Get the latitude and longitude by passing the MCCC,MNC,CELLID


By passing the cellid ,mnc,mcc to get the latitude and longitude of the cell


i wrote this example in .ashx page



public void ProcessRequest(HttpContext context)
        {
            string mcc = "262";
            string mnc = "1";
            string cellid = "45964";
            string url = "http://www.opencellid.org/cell/get?mcc=" + mcc + "&mnc=" + mnc + "&cellid=" + cellid + "";
            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))
                    {
                        string st = reader.ReadToEnd().Trim();
                        if (st != "")
                        {
                            XmlDocument xdoc = new XmlDocument();
                            xdoc.LoadXml(st);
                            XmlElement name = xdoc.GetElementById("45964");
                            XmlNodeList nodeList = xdoc.GetElementsByTagName("cell");
                            int size = nodeList.Count;
                            for (int x = 0; x < size; x++)
                            {
                                string result =         nodeList.Item(x).Attributes.GetNamedItem("lat").Value;
                                string result1 = nodeList.Item(x).Attributes.GetNamedItem("lon").Value;
                                context.Response.Write("Latitude=" + result + ",Longitude=" + result1);
                            }

                        }
                    }
                }
            }
        }


u can also write this in one function also  




For any clarifications or queries please don’t hesitate to call or Email

Phone :- + 91-9492179390


Email :- lannam@technobrainltd.com (or) lokeshtec@gmail.com 
Read More »

Get the Latitude and longitude by passing address

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;
                }
            }
        }

  use above function like

  textbox1.text=GetAddress("hyderabad");



For any clarifications or queries please don’t hesitate to call or Email

Phone :- + 91-9492179390


Email :- lannam@technobrainltd.com (or) lokeshtec@gmail.com 
  
Read More »