0
我發現下面的代碼來調用谷歌地圖的Web服務API: -調用谷歌地圖的Web服務API
public static class Geocoder{
private static string _GoogleMapsKey = Config.getAppSetting(「GoogleMapsKey」);
public static Geolocation? ResolveAddress(string query)
{if (string.IsNullOrEmpty(_GoogleMapsKey))
_GoogleMapsKey = ConfigurationManager.AppSettings["GoogleMapsKey"];
string url = 「http://maps.google.com/maps/geo?q={0}&output=xml&key=」 + _GoogleMapsKey;
url = String.Format(url, query);
XmlNode coords = null;
try{
string xmlString = GetUrl(url);
XmlDocument xd = new XmlDocument();
xd.LoadXml(xmlString);
XmlNamespaceManager xnm = new XmlNamespaceManager(xd.NameTable);
coords = xd.GetElementsByTagName(「coordinates」)[0];
}catch { }
Geolocation? gl = null;
if (coords != null){
string[] coordinateArray = coords.InnerText.Split(‘,’);
if (coordinateArray.Length >= 2)
{gl = new Geolocation(Convert.ToDecimal(coordinateArray[1].ToString()),
Convert.ToDecimal(coordinateArray[0].ToString()));
}
}return gl;
}public static Geolocation? ResolveAddress(string address, string city, string state,
string postcode, string country)
{return ResolveAddress(address + 「,」 + city + 「,」 + state + 「,」 + postcode + 」 「 +
country);}
private static string GetUrl(string url)
{string result = string.Empty;
System.Net.WebClient Client = new WebClient();
using (Stream strm = Client.OpenRead(url))
{StreamReader sr = new StreamReader(strm);
result = sr.ReadToEnd();
}return result;}}
public struct Geolocation
{public decimal Lat;
public decimal Lon;
public Geolocation(decimal lat, decimal lon){
Lat = lat;
Lon = lon;}
public override string ToString()
{return 「Latitude: 「 + Lat.ToString() + 」 Longitude: 「 + Lon.ToString();
}public string ToQueryString()
{return 「+to:」 + Lat + 「%2B」 + Lon;}}
**所以我創建了一個包含上述新模式類代碼,並測試我的工作我已經寫在控制器
Geocoder.ResolveAddress(「University road」,」rajkot」,」gujarat」,」",」India」)
但我仍然不知道如何創建相關的視圖來顯示地圖下面? 在此先感謝您的幫助。**