对我来说这有点奇怪,因为我试图将其输入到我的应用程序中:
"https://embed.windy.com/embed2.html?lat=37.751&lon=-0.854&detailLat=36.751&detailLon=-0.854&width=650&height=450&zoom=10&level=surface&overlay=radar&product=radar&menu=&message=&marker=&calendar=now&pressure=&type=map&location=coordinates&detail=&metricWind=default&metricTemp=default&radarRange=-1";
这非常有效。但是,我想插入我自己的纬度和经度,并使用此代码来执行此操作:
url = "https://embed.windy.com/embed2.html?lat=";
url += latitude;
url += "&lon=";
url += longitude;
url += "&detailLat=";
url += latitude;
url += "&detailLon=";
url += longitude;
url += "&width=650&height=450";
url += "&zoom=10";
url += "&level=surface&overlay=radar&product=radar&menu=&message=&marker=&calendar=now&pressure=&type=map&location=coordinates&detail=&metricWind=default&metricTemp=default&radarRange=-1";
我是这样做的,因为我试图找出问题所在。
当我打印网址时,我得到:
https://embed.windy.com/embed2.html?lat=37.752&lon=-0.854&detailLat=37.752&detailLon=-0.854&width=650&height=450&zoom=10&level=surface&overlay=radar&product=radar&menu=&message=&marker=&calendar=now&pressure=&type=map&location=coordinates&detail=&metricWind=default&metricTemp=default&radarRange=-1
在此打印中,我在纬度和经度中没有逗号:
lat=37.752
lon=-0.854
detailLat=37.752
detailLon=-0.854
到目前为止一切都很好。但是,当我通过 Xcode 上传应用程序时,我可以在 Xcode 日志中看到以下内容:
https://embed.windy.com/embed2.html?lat=37,752&lon=-0,854&detailLat=37,752&detailLon=-0,854&width=650&height=450&zoom=10&level=surface&overlay=radar&product=radar&menu=&message=&marker=&calendar=now&pressure=&type=map&location=coordinates&detail=&metricWind=default&metricTemp=default&radarRange=-1
这里是逗号表面:
lat=37,752
lon=-0,854
detailLat=37,752
detailLon=-0,854
这是我用来设置纬度和经度的基本代码:
latitude = Math.Round((decimal)Utility.setup_List[0].freqSetLocation1.x, 3).ToString();
longitude = Math.Round((decimal)Utility.setup_List[0].freqSetLocation1.y, 3).ToString();
//latitude = Utility.setup_List[0].freqSetLocation1.x.ToString();
//longitude = Utility.setup_List[0].freqSetLocation1.ToString();
我尝试在统一输出中找到逗号,但没有成功。
当我对纬度和经度进行硬编码时,它再次完美运行,但当我按照上面的方式添加纬度和经度时,Xcode 会生成逗号。
这是完整的代码:
public class Radar : MonoBehaviour
{
public GameObject pnl_Background;
public TMP_Text txt_TitleRadar;
public Button btn_RadarGoBack;
public TMP_Text txt_RadarInfo;
private string latitude;
private string longitude;
private string url;
public WellWebView WebView;
public RectTransform image;
private void Start()
{
SetColors();
if (Utility.setup_List[0].isLocations)
{
switch (Utility.processLocationBtnNr)
{
case 1:
txt_RadarInfo.text = Utility.setup_List[0].locationName1 + ", " + Utility.setup_List[0].countryName1;
latitude = Math.Round((decimal)Utility.setup_List[0].setLocation1.x, 3).ToString();
longitude = Math.Round((decimal)Utility.setup_List[0].setLocation1.y, 3).ToString();
break;
case 2:
txt_RadarInfo.text = Utility.setup_List[0].locationName2 + ", " + Utility.setup_List[0].countryName2;
latitude = Math.Round((decimal)Utility.setup_List[0].setLocation2.x, 3).ToString();
longitude = Math.Round((decimal)Utility.setup_List[0].setLocation2.y, 3).ToString();
break;
case 3:
txt_RadarInfo.text = Utility.setup_List[0].locationName3 + ", " + Utility.setup_List[0].countryName3;
latitude = Math.Round((decimal)Utility.setup_List[0].setLocation3.x, 3).ToString();
longitude = Math.Round((decimal)Utility.setup_List[0].setLocation3.y, 3).ToString();
break;
case 4:
txt_RadarInfo.text = Utility.setup_List[0].locationName4 + ", " + Utility.setup_List[0].countryName4;
latitude = Math.Round((decimal)Utility.setup_List[0].setLocation4.x, 3).ToString();
longitude = Math.Round((decimal)Utility.setup_List[0].setLocation4.y, 3).ToString();
break;
}
}
else
{
txt_RadarInfo.text = Utility.setup_List[0].freqLocationName1 + ", " + Utility.setup_List[0].freqCountry;
latitude = Math.Round((decimal)Utility.setup_List[0].freqSetLocation1.x, 3).ToString();
longitude = Math.Round((decimal)Utility.setup_List[0].freqSetLocation1.y, 3).ToString();
//latitude = Utility.setup_List[0].freqSetLocation1.x.ToString();
//longitude = Utility.setup_List[0].freqSetLocation1.ToString();
}
//url = "https://embed.windy.com/embed2.html?lat=" + latitude + "&lon=" + longitude + "&detailLat=" + latitude + "&detailLon=" + longitude + "&width=800&height=1224&zoom=8&level=surface&overlay=radar&product=radar&menu=&message=&marker=&calendar=now&pressure=&type=map&location=coordinates&detail=&metricWind=default&metricTemp=default&radarRange=-1";
//url = "https://embed.windy.com/embed2.html?lat=37.751&lon=-0.854&detailLat=36.751&detailLon=-0.854&width=650&height=450&zoom=10&level=surface&overlay=radar&product=radar&menu=&message=&marker=&calendar=now&pressure=&type=map&location=coordinates&detail=&metricWind=default&metricTemp=default&radarRange=-1";
// https://embed.windy.com/embed2.html?lat=37.752&lon=-0.854&detailLat=37.752&detailLon=-0.854&width=650&height=450&zoom=10&level=surface&overlay=radar&product=radar&menu=&message=&marker=&calendar=now&pressure=&type=map&location=coordinates&detail=&metricWind=default&metricTemp=default&radarRange=-1
url = "https://embed.windy.com/embed2.html?lat=";
url += latitude;
url += "&lon=";
url += longitude;
url += "&detailLat=";
url += latitude;
url += "&detailLon=";
url += longitude;
url += "&width=650&height=450";
url += "&zoom=10";
url += "&level=surface&overlay=radar&product=radar&menu=&message=&marker=&calendar=now&pressure=&type=map&location=coordinates&detail=&metricWind=default&metricTemp=default&radarRange=-1";
print(url);
//print("#" + url.IndexOf(','));
StartRadar();
}
void StartRadar()
{
WellWebView.SetAllowJavaScript(true);
WellWebView.SetJavaScriptCanOpenWindowsAutomatically(true);
WebView = WellWebView.CreateWebView();
WebView.OnFinishedInit += (RaisedWebView) =>
{
// The web view is fully initialized, and you can call the web view methods
WebView.FullScreen = false;
WebView.SetSupportMultipleWindows(true);
WebView.SetTargetRect(image);
WebView.Android.SetUseWideViewPort(true);
WebView.Android.SetLoadWithOverviewMode(true);
WebView.IOS.AllowBackForwardNavigationGestures(true);
WebView.LoadUrl(url);
WebView.Show();
};
WebView.Init();
}
void SetColors()
{
pnl_Background.GetComponent<Image>().color = Utility.backgroundColor;
txt_TitleRadar.color = Utility.foregroundColor;
txt_RadarInfo.color = Utility.foregroundColor;
btn_RadarGoBack.image.color = Utility.foregroundColor;
}
public void BTN_RadarGoBack()
{
WebView.StopLoading();
WebView.Destroy();
SceneManager.LoadScene("WeatherList");
}
}
顺便说一句,我使用 Unity 资源 WellWebView 来显示雷达图。
最佳答案
将 CultureInfo.InvariantCulture
传递给您的 .ToString()
方法。
latitude = Math.Round((decimal)Utility.setup_List[0].freqSetLocation1.x, 3).ToString(CultureInfo.InvariantCulture);
longitude = Math.Round((decimal)Utility.setup_List[0].freqSetLocation1.y, 3).ToString(CultureInfo.InvariantCulture);
关于c# - 当我找不到逗号时如何将逗号更改为点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75519397/