【问题标题】:how to find latitude and longitude of a place in wp7如何在wp7中找到一个地方的经纬度
【发布时间】:2013-02-05 12:08:19
【问题描述】:

如何在 Wp7 中查找地址的经纬度

前:

如果我给出位置名称:“纽约”,那么我想得到它的纬度和经度。

提前致谢

【问题讨论】:

    标签: windows-phone-7 geolocation gps


    【解决方案1】:

    这应该可行:

    用于反序列化 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

    【讨论】:

    • 感谢您的回答:)
    【解决方案2】:
    WebClient webClient = new WebClient();
    string xml = webClient.DownloadString("http://nominatim.openstreetmap.org/search?city=%22new%20york%22&format=xml");
    

    【讨论】:

    • 你以前用过这个来获取纬度和经度吗??
    【解决方案3】:

    也许你可以使用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 格式的结果

    【讨论】:

    • 对 WP7 非常陌生,如何从 c# 调用此 url
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多