Search code examples
androidxamarindevelopment-environment

How to display google maps in Android (which takes to current location and show the distance to destination)


switch (Device.RuntimePlatform)
            {
                case Device.iOS:
                    url = String.Format("https://maps.apple.com/maps?daddr={0}", Uri.EscapeDataString(Shop.Address.StreetZipCityString));
                    break;
                case Device.Android:

                    url = String.Format("geo:0,0?q={0}", Uri.EscapeDataString(Shop.Address.StreetZipCityString));

                    break;
                default:
                    url = String.Format("https://www.google.com/maps/dir/?api=1&query={0}", Uri.EscapeDataString(Shop.Address.StreetZipCityString));
                    break;

            }

In IOS this URL takes me to current location and show the destination too. In android only destination is being shown not the current location or distance from the current to destination.


Solution

  • I think that you need to encode destination address using HttpUtility.UrlEncode can you try url = String.Format("geo:0,0?q={0}", Uri.EscapeDataString(HttpUtility.UrlEncode(Shop.Address.StreetZipCityString)));