xamarin.android - 路线 API 无法在物理设备上运行
问题描述
我在 Xamarin.Android 上编写了一个应用程序。在模拟器上调试时,Directions API 可以完美运行。但是在物理设备上测试时它不起作用。我想问题可能出在http请求中。有人熟悉这样的问题吗?
public async Task<string> GetDirectionJsonAsync(LatLng location, LatLng destLocation, string mapkey)
{
// Origin of route
string str_origin = "origin=" + location.Latitude.ToString() + "," + location.Longitude.ToString();
// Destination of route
string str_destination = "destination=" + destLocation.Latitude.ToString() + "," + destLocation.Longitude.ToString();
// Mode
string mode = "mode=driving";
string parameters = str_origin + "&" + str_destination + "&" + mode + "&key=" + mapkey;
// Output
string output = "json";
string url = "https://maps.googleapis.com/maps/api/directions/" + output + "?" + parameters;
var handler = new HttpClientHandler();
HttpClient client = new HttpClient(handler);
string jsonString = await client.GetStringAsync(url);
return jsonString;
}
解决方案
推荐阅读
- sql - SQL Server:SQL 作业每天运行一次。如果多次运行将产生错误 cannot insert duplicate key in object
- c++ - 从 RSU 发送消息时,如何调用 onWSM 方法?
- c++ - 查找用户输入值的总和
- keycloak - 为使用 Keycloak 配置的 OTP 生成备份代码
- django - 安全过滤器仍显示 HTML 标签
- r - 使用 grep 函数根据另一列中的匹配字符串创建新列
- python - Pytorch CUDA 错误:配置参数无效
- macos - MacOS Mojave 上 pgadmin4 config_local.py 的位置
- python - 避免通过就地操作修改参数的有效方法
- javascript - Boostrap 4 下拉动画