Хорошо, я использую Lockito из магазина приложений andriod, чтобы смоделировать свое местоположение, и я получаю первый long и lat, но он не обновляется, так как я должен сохранять местоположение в списке
Эта функция locationObtained не вызывается более одного раза.
Я использую реальное устройство для тестирования и предоставил разрешение на определение местоположения.
private async Task<int> StartGps()
{
var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);
if (status != PermissionStatus.Granted)
{
if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location))
{
await DisplayAlert("Need location", "Gunna need that location", "OK");
}
var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Location);
status = results[Permission.Location];
}
ILocation loc = DependencyService.Get<ILocation>();
loc.locationObtained += (object ss, ILocationEventArgs ee) =>
{
lat = ee.lat;
lng = ee.lng;
lbllat.Text = ee.lat.ToString();
lbllong.Text = ee.lng.ToString();
Position position = new Position(lat, lng);
postionsList.Add(position);
};
listPostions.ItemsSource = postionsList;
loc.ObtainMyLocation();
return 1;
}
В моемListview У меня есть следующее.
<ListView x:Name="listPostions" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout BackgroundColor="#eee"
Orientation="Vertical">
<StackLayout Orientation="Horizontal">
<Label Text="{Binding Latitude}"
TextColor="#f35e20" />
<Label Text="{Binding Longitude}"
HorizontalOptions="EndAndExpand"
TextColor="#503026" />
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Проблема заключается в том, что у меня нет автоматического обновления моего приложения. У меня есть seti lockito, чтобы быть выбранным приложением в опциях разработчика, на котором у меня есть местоположение, и я могу видеть движение в Lockito нормально, но яЯ не могу видеть, как другие приложения из Локкито входят в мое приложение.
Это моя функция andriod
public class GetMyLocation : Java.Lang.Object, ILocation, ILocationListener
{
public event EventHandler<ILocationEventArgs> locationObtained;
public void ObtainMyLocation()
{
LocationManager lm = (LocationManager)Forms.Context.GetSystemService(Context.LocationService);
lm.RequestLocationUpdates(LocationManager.NetworkProvider,0, 0, this);
}
public void OnLocationChanged(Location location)
{
if (location != null)
{
LocationEventArgs args = new LocationEventArgs();
args.lat = location.Latitude;
args.lng = location.Longitude;
locationObtained(this, args);
}
}
public void OnProviderDisabled(string provider)
{
}
public void OnProviderEnabled(string provider)
{
}
public void OnStatusChanged(string provider, [GeneratedEnum] Availability status, Bundle extras)
{
}
}