Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Basically what I have been trying to accomplish is passing the latitude and longitude to a google maps control to display the location. These coordinates were generated from a street address, city, state, zipcode using this following method
C#
public static GeocoderLocation Locate(string query)
        {
            WebRequest request = WebRequest
               .Create("http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address="
                  + HttpUtility.UrlEncode(query));

            using (WebResponse response = request.GetResponse())
            {
                using (Stream stream = response.GetResponseStream()) //The GetResponseStream of the System.IO.Stream is used to get the stream from the server which is used and read as
                                                                     //the body of the response. The stream itself is what contains the body of the response.
                {
                    XDocument document = XDocument.Load(new StreamReader(stream));

                    XElement longitudeElement = document.Descendants("lng").FirstOrDefault();
                    XElement latitudeElement = document.Descendants("lat").FirstOrDefault();

                    if (longitudeElement != null && latitudeElement != null)
                    {
                        return new GeocoderLocation
                        {
                            Longitude = Double.Parse(longitudeElement.Value, CultureInfo.InvariantCulture),
                            Latitude = Double.Parse(latitudeElement.Value, CultureInfo.InvariantCulture)
                        };
                    }
                }
            }

            return null;
        }


At this point I am getting the following error:
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Cannot create an object of type 'System.Nullable`1[[System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' from its string representation 'lat' for the 'Latitude' property.

At this point, I have been trying to figure this out through searching different solutions for around 20 hours over the past few days.

Any help would be appreciated. This is my first time doing anything with Google Maps API.

What I have tried:

On the source side of the aspx page I used the following code,
ASP.NET
<form id="form1" runat="server">
        <div>
            

            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            
            <map:GoogleMap ID="GoogleMap1" runat="server" MapType="Hybrid" Zoom="8" Latitude="lat" Longitude="lng" CssClass="map" Width="100%" Height="100%" FullscreenControl="true" ApiKey="ApiKey">
              
            </map:GoogleMap>

            
            
        </div>
        

        </form>
however, it doesn't seem to be able to get the latlng coordinates from the aspx.cs file.
Posted
Comments
Richard MacCutchan 5-Feb-19 4:59am    
Look at the line where the error occurred and check the value of all references and variables.
josephcj87 7-Feb-19 10:30am    
Thank you I was able to get this figured out.
Richard MacCutchan 7-Feb-19 10:37am    
How about posting the solution so other people can benefit from your experience? These forums only work if everyone tries to help everyone else.
Member 15530332 10-Feb-22 8:14am    
Hello, would you publish the solution ? and maybe you would give me a hand with my question?

https://www.codeproject.com/Questions/5324782/How-do-I-pass-my-coordinates-from-mo-to-the-view-t

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