[英]get Zero as longitude and latitude with every address in .net
在我的asp.net應用程序中,我正在使用Geocode查找給定地址的緯度和經度,並將其保存在數據庫中。 十分奇怪的是,它在過去8個月中一直運行良好,但突然從第2天起,即使我嘗試使用它正在工作的舊地址,但對於我們提供的每個地址,它都返回零,但現在它也返回了經度和零。緯度。
請讓我知道如何解決此問題
這是我正在使用的代碼,以前可以使用,我沒有做任何更改
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]));
}
}
嗨,里納(Reena),我也一個月前收到了同樣的問題,但是我只更改了這一部分,請檢查一下。
latitude = results[0].geometry.location.Ya;
longlitude = results[0].geometry.location.Za;
將斷點保持在此結果附近,並檢查您得到了什么。 希望這對您有幫助
您一直在使用地理編碼版本v2,現在google將其版本升級到了v3。
版本2不再存在。 狀態碼610,地理編碼
檢查下面的鏈接以獲取更多詳細信息https://developers.google.com/maps/documentation/geocoding/#Results
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.