Click here to Skip to main content
15,741,892 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to find latitude and longitude of location which is displaying on datalist from database.
on click of linkbutton of datalist i am getting location and i want to find latitude and longitude of that location using google map v3 API. I have API also. dont want javascrpt code is any other way? i am trying foolowing code but it fails..
Label lblcountryHOout = (Label)DsListHOoutlet.Items[e.Item.ItemIndex].FindControl("LblCountryHOoutlet");
            string countryHOout = lblcountryHOout.Text;
            Label lblcityHOout = (Label)DsListHOoutlet.Items[e.Item.ItemIndex].FindControl("LblCityHOoutlet");
            string cityHOout = lblcityHOout.Text;
            Label lbladdressHOout = (Label)DsListHOoutlet.Items[e.Item.ItemIndex].FindControl("LblAddressHOoutlet");
            string addressHOout = lbladdressHOout.Text;

            string location = countryHOout + "," + cityHOout;

            string appId = "API Key";
            string url = string.Format("{0}&key=key &sensor=TRUE OR FALSE", Server.UrlEncode(location), appId,false);

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
             WebResponse response = request.GetResponse();                
                XDocument xdoc = XDocument.Load(url);

                // Verify the GeocodeResponse status
                //string status = xdoc.Element("GeocodeResponse").Element("status").Value;
                //ValidateGeocodeResponseStatus(status, address);              

                XElement locationElement = xdoc.Element("GeocodeResponse").Element("result").Element("geometry").Element("location");
                latitude1 = (double)locationElement.Element("lat");
                longitude1 = (double)locationElement.Element("lng");

           catch (System.Net.WebException exp)


XML file is not retriving correct at the URL "[^]"

it is retiving like and givivng messageas follows
This XML file does not appear to have any style information associated with it. The document tree is shown below.

the xml should retrive latitude and longitude what to do? plz help..
Updated 10-Jul-13 2:04am

Share this answer
You have to use Javascript on the client side to get the lat and long using the Google Maps API V3.0

As far as I know, the api call uses ajax or something to fetch the data,

the object is below, and the lat and long is in the geometry location

 var vA = $('[id*="_txt_JQuery_Google_Address_Destination"]').val();
 var geocoder = new google.maps.Geocoder();
    geocoder.geocode({ 'address': vA }, function (results, status) {
    if (status != google.maps.GeocoderStatus.OK) {
     // Examine the error and make the needed corrections
     alert("Initial geocode request was not successful for the following reason: " + status);
    else {
     // results are in the arrray below 


You may have to look for another source for geocoding, one that supports just a regular call to a web service, using

You would have to reverse engineer the google map object, to fetch to parameters for it.

If you need just one set of geocode, then you call fetch the geocode in page load and opulate a hidden textbox, and then use to get the values.

[edit 2]

Now that I think about it, you could use .onclientClick = "fetch_GeoCode(address); return false;"

and run the Google Maps API to just get the geocode, and populate the hidden textboxes, you don't have have to draw a map technically.

There seems to be a ton of stuff out there for it, it would be and location.long[^]
Share this answer

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