Xamarin Forms Geocode Android

馋奶兔 提交于 2019-12-24 19:23:07

问题


I Have two pieces of code, one to get adresses from a position & one to get position from adress.

GetAddressesForPosition

 var geoCoder = new Geocoder();

            Task.Run(async () =>
            {
                var possibleAddresses = await geoCoder.GetAddressesForPositionAsync(position);

                Device.BeginInvokeOnMainThread(() =>
                {
                    var firstAdress = possibleAddresses.FirstOrDefault();
                    GeolocationAdressEntry.Text = firstAdress;
                    //GeolocationAdressEntry.Text = $@"{firstAdresse.} {firstAdresse.PostalCode} {firstAdresse.Locality}";
                });

            });

For this code, I not have any exception and the code never goes after

var possibleAddresses = await geoCoder.GetAddressesForPositionAsync(position); 

GetPositionsForAddress

var elem = (Entry)sender;
            var geoCoder = new Geocoder();

            IEnumerable<Xamarin.Forms.Maps.Position> loc;

            try
            {
                loc = await geoCoder.GetPositionsForAddressAsync(elem.Text);

                var firstLoc = loc.FirstOrDefault();
                var adress = elem.Text;

                CreateNewPin(firstLoc, adress);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

For this one it thrown an error : "grpc failed". If needed I can post the complete error.

This is boring because it works perfectly in IOS.

I tried on emulators ( Genymotion & adb ) with different versions and also in a true device. Same issue.


回答1:


The issue comes from the emulator. Code work in a true device.



来源:https://stackoverflow.com/questions/45894719/xamarin-forms-geocode-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!