i am getting one issue in my app.i am trying to retrieve my current position(Using Mvvm) and pass it to my custom renderer but when try to call below code
if (locator.IsGeolocationAvailable && locator.IsGeolocationEnabled) { CustomPinResponse objresponse = new CustomPinResponse(); var pos = await locator.GetPositionAsync(TimeSpan.FromSeconds(5), null); if (pos != null) { double lat = pos.Latitude; double lon = pos.Longitude; objresponse = await App.GoogleApiBALObject.GetPlaceUsingWord(lat, lon, "hospital"); if (objresponse.Success == true) { for (int i = 0; i < objresponse.Data.Count; i++) { ListCustomPins = new ObservableCollection<CustomPin> { objresponse.Data[i] }; } } else await App.dialogManager.ShowMessage(objresponse.ErrorMessage.ToString(), ""); } }
before retrieve my current position my uwp custom renderer call and could not get any data.
my custom renderer is as below
` protected override void OnElementChanged(ElementChangedEventArgs
if (e.OldElement != null)
{
nativeMap.MapElementClick -= OnMapElementClick;
nativeMap.Children.Clear();
mapOverlay = null;
nativeMap = null;
}
if (e.NewElement != null)
{
var formsMap = (ModifyMap)e.NewElement;
nativeMap = Control as MapControl;
customPins = formsMap.Items;
nativeMap.Children.Clear();
nativeMap.MapElementClick += OnMapElementClick;
if (customPins != null)
{
foreach (var pin in customPins)
{
var snPosition = new BasicGeoposition { Latitude = pin.Pin.Position.Latitude, Longitude = pin.Pin.Position.Longitude };
var snPoint = new Geopoint(snPosition);
var mapIcon = new MapIcon();
mapIcon.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/pin.png"));
mapIcon.CollisionBehaviorDesired = MapElementCollisionBehavior.RemainVisible;
mapIcon.Location = snPoint;
mapIcon.NormalizedAnchorPoint = new Windows.Foundation.Point(0.5, 1.0);
nativeMap.MapElements.Add(mapIcon);
}
}
}
}`
Please help me i tried to search on google but not found any proper solution.