【发布时间】:2013-02-05 12:08:19
【问题描述】:
如何在 Wp7 中查找地址的经纬度
前:
如果我给出位置名称:“纽约”,那么我想得到它的纬度和经度。
提前致谢
【问题讨论】:
标签: windows-phone-7 geolocation gps
如何在 Wp7 中查找地址的经纬度
前:
如果我给出位置名称:“纽约”,那么我想得到它的纬度和经度。
提前致谢
【问题讨论】:
标签: windows-phone-7 geolocation gps
这应该可行:
用于反序列化 json 字符串的类
public class PlaceInfo
{
public string place_id { get; set; }
public string licence { get; set; }
public string osm_type { get; set; }
public string osm_id { get; set; }
public List<string> boundingbox { get; set; }
public string lat { get; set; }
public string lon { get; set; }
public string display_name { get; set; }
public string @class { get; set; }
public string type { get; set; }
public double importance { get; set; }
public string icon { get; set; }
}
这是从网站获取信息的代码: 格式是JSON,我用的是c#的json序列化器
使用 System.Runtime.Serialization; 使用 System.Runtime.Serialization.Json;
WebClient webClient = new WebClient();
string jsonString = webClient.DownloadString("http://nominatim.openstreetmap.org/search?city=%22new%20york%22&format=json");
//load into memorystream
using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(jsonString)))
{
//parse
var ser = new DataContractJsonSerializer(typeof(PlaceInfo[]));
PlaceInfo[] obj = (PlaceInfo[])ser.ReadObject(ms);
}
数组 obj 现在具有使用该名称找到的所有位置。例如 jsut 占据第一位,找到 obj[0].lon 和 obj[0].lat
【讨论】:
WebClient webClient = new WebClient();
string xml = webClient.DownloadString("http://nominatim.openstreetmap.org/search?city=%22new%20york%22&format=xml");
【讨论】:
也许你可以使用openstreetmaps:
http://nominatim.openstreetmap.org/search?city=%22new%20york%22&format=json
http://nominatim.openstreetmap.org/search?city="---cityname---"&countrycodes="---CountryCode---"&limit=2&format=json
http://wiki.openstreetmap.org/wiki/Nominatim
你可以得到 json 或 xml 格式的结果
【讨论】: