Click here to Skip to main content
14,028,405 members
Rate this:
Please Sign up or sign in to vote.
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
public static GeocoderLocation Locate(string query)
            WebRequest request = WebRequest
                  + 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=, 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,
<form id="form1" runat="server">

            <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">


however, it doesn't seem to be able to get the latlng coordinates from the aspx.cs file.
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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.190419.4 | Last Updated 4 Feb 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100