简体   繁体   中英

get Zero as longitude and latitude with every address in .net

In my asp.net application I was using Geocode to find latitude and longitude for given address and was saving these in database. Its very strange that, its was working perfectly from last 8 month but suddenly from 2 days its returning Zero for every address we are providing even i had tried with old addresses for which it was working but now for that also its returning zero as longitude and latitude.

Please let me know how to fix this problem

Here is the code i am using, which was working before, I have not changed anything

public interface ISpatialCoordinate
{
    decimal Latitude { get; set; }
    decimal Longitude { get; set; }
}

/// <summary>
/// Coordiate structure. Holds Latitude and Longitude.
/// </summary>
public struct Coordinate : ISpatialCoordinate
{
    private decimal _latitude;
    private decimal _longitude;

    public Coordinate(decimal latitude, decimal longitude)
    {
        _latitude = latitude;
        _longitude = longitude;
    }

    #region ISpatialCoordinate Members

    public decimal Latitude
    {
        get
        {
            return _latitude;
        }
        set
        {
            this._latitude = value;
        }
    }

    public decimal Longitude
    {
        get
        {
            return _longitude;
        }
        set
        {
            this._longitude = value;
        }
    }

    #endregion
}

public class Geocode
{

    private const string _googleUri = "https://maps.google.com/maps/geo?q=";
    private const string _outputType = "csv"; // Available options: csv, xml, kml, json
    //
    private const string _googleKey = ""; //here i am giving my key

    /// <summary>
    /// Returns a Uri of the Google code Geocoding Uri.
    /// </summary>
    /// <param name="address">The address to get the geocode for.</param>
    /// <returns>A new Uri</returns>
    private static Uri GetGeocodeUri(string address)
    {
       // string googleKey = ConfigurationManager.AppSettings["googleApiKey"].ToString();
        address = HttpUtility.UrlEncode(address);
        return new Uri(String.Format("{0}{1}&output={2}&key={3}", _googleUri, address, _outputType, _googleKey));
    }

    /// <summary>
    /// Gets a Coordinate from a address.
    /// </summary>
    /// <param name="address">An address.
    ///     <remarks>
    ///         <example>
    ///         3276 Westchester Ave, Bronx, NY 10461
    /// 
    ///         or 
    /// 
    ///         New York, NY 
    /// 
    ///         or
    /// 
    ///         10461  (just a zipcode)
    ///         </example>
    ///     </remarks>
    /// </param>
    /// <returns>A spatial coordinate that contains the latitude and longitude of the address.</returns>
    public static Coordinate GetCoordinates(string address)
    {
        WebClient client = new WebClient();
        Uri uri = GetGeocodeUri(address);

        /*  The first number is the status code, 
         * the second is the accuracy, 
         * the third is the latitude, 
         * the fourth one is the longitude.
         */
        string[] geocodeInfo = client.DownloadString(uri).Split(',');

        return new Coordinate(Convert.ToDecimal(geocodeInfo[2]), Convert.ToDecimal(geocodeInfo[3]));
    }

}

hi Reena I too received the same issue a month back but i changed only this particular portion Please check this out.

latitude = results[0].geometry.location.Ya;
longlitude = results[0].geometry.location.Za;

Keep break point near this result and Check what you are Getting. Hope this Help you

you have been using Geocoding Version v2 Now google upgraded its version to v3.

  • Using this version you cannot get ourput Directly as csv
  • Either you want to go with xml or Json method.
  • Better go with XML its easy to Parse the Data

Version 2 no longer exists. status code 610, geocode

Check the Below link for more details https://developers.google.com/maps/documentation/geocoding/#Results

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM