C# 反向地理定位未返回正确的国家/地区名称

C# 反向地理定位未返回正确的国家/地区名称,c#,android,google-maps,unity3d,reverse-geocoding,C#,Android,Google Maps,Unity3d,Reverse Geocoding,我正在与谷歌地图反向地理定位联合工作,以查找输入的经纬度的国家名称 我通过Inspector输入来自世界各地的位置来测试代码。 每次,它都会输出国家的名称(如英国、美国、法国、新加坡等)。 但是,当我输入俄文lat和long时,它只返回一个数字。 这个号码原来是该地区的邮政编码 这是我正在使用的代码: private string GoogleAPIKey = "MY KEY"; public string latitude; public string longitud

我正在与谷歌地图反向地理定位联合工作,以查找输入的经纬度的国家名称

我通过Inspector输入来自世界各地的位置来测试代码。 每次,它都会输出国家的名称(如英国、美国、法国、新加坡等)。 但是,当我输入俄文lat和long时,它只返回一个数字。 这个号码原来是该地区的邮政编码

这是我正在使用的代码:

 private string GoogleAPIKey = "MY KEY";

     public string latitude;
     public string longitude;
 private string countryLocation;
 public Text console;

     IEnumerator Start()
    {
         if (!Input.location.isEnabledByUser){

             yield break;          
        }
         Input.location.Start();

         int maxWait = 20;

         while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
         {
           yield return new WaitForSeconds(1);
             maxWait--;
         }
         if (maxWait < 1)
         {
             yield break;
         }
         if (Input.location.status == LocationServiceStatus.Failed)
         {
                 yield break;
         }
         else
         {

             longitude = Input.location.lastData.longitude.ToString();
             latitude = Input.location.lastData.latitude.ToString();
           console.text += (latitude + " " + longitude);
         }
         Input.location.Stop();

         using (WWW www = new WWW("https://maps.googleapis.com/maps/api/geocode/json?latlng=" +latitude +","+ longitude   + "&key=" + GoogleAPIKey)){
             yield return www;

             if(www.error == null)
             {
                 var location =  Json.Deserialize(www.text) as Dictionary<string, object>;
                 var locationList = location["results"] as List<object>;
                 var locationListing = locationList[0] as Dictionary<string, object>;
                      countryLocation = locationListing["formatted_address"].ToString().Substring(locationListing["formatted_address"].ToString().LastIndexOf(",")+2);

                   console.text += (" LOCATION IS: " + countryLocation.ToString());
             }else{
                console.text += www.error;
            }
         };

    }
私有字符串GoogleAPIKey=“我的密钥”;
公共字符串纬度;
公共字符串经度;
私人位置;
公共文本控制台;
IEnumerator Start()
{
如果(!Input.location.isEnabledByUser){
屈服断裂;
}
Input.location.Start();
int maxWait=20;
while(Input.location.status==LocationServiceStatus.Initializing&&maxWait>0)
{
返回新的WaitForSeconds(1);
maxWait--;
}
if(maxWait<1)
{
屈服断裂;
}
if(Input.location.status==LocationServiceStatus.Failed)
{
屈服断裂;
}
其他的
{
经度=Input.location.lastData.longitude.ToString();
latitude=Input.location.lastData.latitude.ToString();
console.text+=(纬度+“”+经度);
}
Input.location.Stop();
使用(WWW=newwww)https://maps.googleapis.com/maps/api/geocode/json?latlng=“+纬度+”、“+经度+”&key=“+GoogleAPIKey)){
收益率;
如果(www.error==null)
{
var location=Json.反序列化(www.text)为字典;
var locationList=位置[“结果”]作为列表;
var locationListing=locationList[0]作为字典;
countryLocation=locationListing[“formatted_address”].ToString().Substring(locationListing[“formatted_address”].ToString().LastIndexOf(“,”)+2);
console.text+=(“位置为:”+countryLocation.ToString());
}否则{
console.text+=www.error;
}
};
}
我已经厌倦了俄罗斯的几个地方,它只输出数字。
我不知道其他国家是否会发生这种情况,但我尝试过的其他国家工作正常并输出了国家名称。

将格式化地址解析为字符串并不是获取国家名称的最佳方法,因为正如您所发现的,俄罗斯地址以邮政编码结尾。国家名称作为一个单独的对象提供在
地址\u组件中

您要检索
结果。地址组件[]。长名称
其中
类型
[国家,政治]

以下是显示国家/地区对象的简短回复:

{
   "plus_code": {
      "compound_code": "9XMF+9P Yegoryevsk, Moscow Oblast, Russia",
      "global_code": "9G7W9XMF+9P"
   },
   "results": [
      {
         "address_components": [
            {
               "long_name": "Russia",
               "short_name": "RU",
               "types": [
                  "country",
                  "political"
               ]
            }
         ],
         "formatted_address": "Unnamed Road, Moskovskaya oblast', Russia, 140301",
       }
   ],
   "status": "OK"
}

将格式化地址解析为字符串并不是获取国家名称的最佳方法,因为正如您所发现的,俄语地址以邮政编码结尾。国家名称作为一个单独的对象提供在
地址\u组件中

您要检索
结果。地址组件[]。长名称
其中
类型
[国家,政治]

以下是显示国家/地区对象的简短回复:

{
   "plus_code": {
      "compound_code": "9XMF+9P Yegoryevsk, Moscow Oblast, Russia",
      "global_code": "9G7W9XMF+9P"
   },
   "results": [
      {
         "address_components": [
            {
               "long_name": "Russia",
               "short_name": "RU",
               "types": [
                  "country",
                  "political"
               ]
            }
         ],
         "formatted_address": "Unnamed Road, Moskovskaya oblast', Russia, 140301",
       }
   ],
   "status": "OK"
}

你能提供你尝试过的并证明问题的纬度、长余弦值吗?你能提供你尝试过并证明问题的纬度、长余弦值吗?谢谢@Dan Wilson这似乎是解决问题的方法。我得想办法把它翻译成C!谢谢@Dan Wilson这似乎是一种方法。我得想办法把它翻译成C!