Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ReverseGeocodeQuery使用与系统语言不同的语言生成结果_C#_Windows Phone 8_Windows Phone_Cultureinfo_Reverse Geocoding - Fatal编程技术网

C# ReverseGeocodeQuery使用与系统语言不同的语言生成结果

C# ReverseGeocodeQuery使用与系统语言不同的语言生成结果,c#,windows-phone-8,windows-phone,cultureinfo,reverse-geocoding,C#,Windows Phone 8,Windows Phone,Cultureinfo,Reverse Geocoding,我正在使用ReverseGeocodeQuery类从坐标中获取位置名称: ReverseGeocodeQuery query = new ReverseGeocodeQuery(); query.GeoCoordinate = new GeoCoordinate(latitude, longitude); query.QueryCompleted += (sender, args) => { var result = args.Result[0].Information.Addre

我正在使用
ReverseGeocodeQuery
类从坐标中获取位置名称:

ReverseGeocodeQuery query = new ReverseGeocodeQuery();
query.GeoCoordinate = new GeoCoordinate(latitude, longitude);
query.QueryCompleted += (sender, args) =>
{
    var result = args.Result[0].Information.Address;
    Location location = new Location(result.Street, result.City, result.State, result.Country);
};            
query.QueryAsync();
问题是结果是以手机的系统语言返回的。因为我使用地名来标记,所以我需要所有地名都使用同一种语言,最好是英语

我已尝试将
CurrentCulture
设置为
en-US

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
但我仍然使用配置为系统语言的语言获得结果


是否有任何方法可以用所需的语言从
ReverseGeocodeQuery
获取结果?

结果始终使用系统语言。也许你可以保存地点的名称和长度,或者使用翻译服务翻译成英语来完成Josue的回答。以desided语言获取反向地理编码结果的另一种方法是使用允许指定该结果的公共REST API之一(如此处的Google或Nokia)。虽然它们的使用很简单,而且非常可定制,但缺点是需要注册到服务才能获得密钥

我已经决定使用这里的API。因此,在下面,您会发现我使用的代码实现了与使用问题中的代码相同的结果,但强制结果为英语:

using (HttpClient client = new HttpClient())
{
    string url = String.Format("http://reverse.geocoder.cit.api.here.com/6.2/reversegeocode.json"
                    + "?app_id={0}"
                    + "&app_code={1}"
                    + "&gen=1&prox={2},{3},100"
                    + "&mode=retrieveAddresses"
                    + "&language=en-US", 
                    App.NOKIA_HERE_APP_ID, App.NOKIA_HERE_APP_CODE, latitude.ToString(CultureInfo.InvariantCulture), longitude.ToString(CultureInfo.InvariantCulture));

    var response = await client.GetAsync(url);
    var json = await response.Content.ReadAsStringAsync();
    dynamic loc = JObject.Parse(json);               
    dynamic address = JObject.Parse(loc.Response.View[0].Result[0].Location.Address.ToString());

    string street = address.Street;
    string city = address.City;
    string state = address.State;
    string country = address.Country;

    Location location = new Location(street, city, state, country);
}

我最终选择了使用诺基亚的API,在这里您可以指定语言。缺点是需要在服务中注册。我在下面添加了代码。