在 Android 上调试时请求无效,Xamarin

Invalid Request when debuging on Android devide, Xamarin

我正在用 Xamarin Forms 编写一个项目,今天我们在 Android 设备上试用我们的应用程序。我们对 googleAPI 的请求停止工作。这是代码:

HttpWebRequest webRequest = WebRequest.Create(@"https://maps.googleapis.com/maps/api/place/search/json?location=" + position.Latitude + "," + position.Longitude + "&radius=1000&types=bar&sensor=false&key=APIKEY") as HttpWebRequest;
webRequest.Method = "GET";
webRequest.BeginGetResponse(new AsyncCallback(RequestCompleted), webRequest);

然后:

var request = (HttpWebRequest)result.AsyncState;
var response = (HttpWebResponse)request.EndGetResponse(result);
using (var stream = response.GetResponseStream())
{
var r = new StreamReader(stream);
var resp = r.ReadToEnd();
}

我们收到回复并将其更改为 json。在计算机上它工作正常,但在 Android 上它说无效请求。有人使用 Xamarin 并知道如何解决它吗?

如果非要我猜的话,我会猜,你 phone 上的语言环境/语言与你电脑上的不同。

HttpWebRequest webRequest = WebRequest.Create(@"https://maps.googleapis.com/maps/api/place/search/json?location=" + position.Latitude + "," + position.Longitude + "&radius=1000&types=bar&sensor=false&key=APIKEY") as HttpWebRequest; 

...n=" + position.Latitude + "," + position.Longitude + "&ra... 处有隐含的 ToString() 产生本地化输出。但是 google API 需要带有 . 作为小数点分隔符的值。

附加.ToString("G", CultureInfo.InvariantCulture)

HttpWebRequest webRequest = WebRequest.Create(@"https://maps.googleapis.com/maps/api/place/search/json?location=" + 
position.Latitude.ToString("G", CultureInfo.InvariantCulture) + 
"," + position.Longitude.ToString("G", CultureInfo.InvariantCulture) +
"&radius=1000&types=bar&sensor=false&key=APIKEY") as HttpWebRequest;