0
私はGps座標を一度オフに照会するアプリを書いています。私の問題は、アプリケーションがGPSサービスをリリースしないことがあることです。 GPSアイコンは画面上に永遠に残っています。考えられる原因は何でしょうか?以下は私のコードです:Xamarin GPSサービスを解放する方法
string latitude = string.Empty;
string longitude = string.Empty;
string Area = string.Empty;
Geocoder geoCoder = null;
IGeolocator locator = null;
try
{
//get gps
string myGps = string.Empty;
locator = CrossGeolocator.Current;
locator.DesiredAccuracy = 50;
TimeSpan sp = new TimeSpan(10000);
var position = await locator.GetPositionAsync(sp);
latitude = position.Latitude.ToString();
longitude = position.Longitude.ToString();
geoCoder = new Geocoder(this.ApplicationContext);
var addresses = geoCoder.GetFromLocation(position.Latitude, position.Longitude, 1);
if (addresses != null)
Area = addresses[0].CountryName + ", " + addresses[0].Locality + ", " + addresses[0].SubLocality + ", " + addresses[0].FeatureName;
successful = true;
}
catch (Exception ex)
{
}
私はあなたのソリューションを試してみました。私はまだこの問題を経験しています。 –
さて、タイムアウトを10秒にして、すべてのコードをtry catchブロックに入れようとしましたか? 何か問題が発生した場合は、例外を取得する必要がありますし、多分それはhaopenを理解するのに役立ちます。 – NourB
はい、私はtry catchに自分のコードを入れました。私は何の誤りもありません。どこでタイムアウトを設定できますか?どのオブジェクトですか? –