Forum Cross Platform with Xamarin

Click event on map in Xamarin.Forms.Maps

I've been searching the forums and so far been unable to find a way of getting a lat/long from a user clicking on a map

Just find this baffling since there doesn't appear to be a formal way of doing it - closest I've seen is a 3rd party plugin called TK

Is there really no official method for doing this? Seems so obvious ...

Answers

  • DarshanJSDarshanJS USMember ✭✭✭✭
    edited February 2018

    @Journeyman said:
    I've been searching the forums and so far been unable to find a way of getting a lat/long from a user clicking on a map

    Just find this baffling since there doesn't appear to be a formal way of doing it - closest I've seen is a 3rd party plugin called TK

    Is there really no official method for doing this? Seems so obvious ...

    If you know proper address you can implement below code
    If you wish you can do it in simple way, no need any plugins,

    pass your address using below code

            var address = "which ever address you want to show";
    
                    switch (Device.RuntimePlatform)
                    {
                        case Device.iOS:
                            Device.OpenUri(
                            new Uri(string.Format("http://maps.apple.com/?q={0}", WebUtility.UrlEncode(address))));
                            break;
                        case Device.Android:
                            Device.OpenUri(
                            new Uri(string.Format("geo:0,0?q={0}",
                           WebUtility.UrlEncode(address))));
                            break;
    
                        case Device.WinPhone:
                            Device.OpenUri(
                            new Uri(string.Format("bingmaps:?where={0}",
                           Uri.EscapeDataString(address))));
                            break;
                    }
    
  • JourneymanJourneyman GBMember ✭✭

    not sure what you mean by 'if you know the address'? I simply want the lat/long based on the x,y coo-rdinates of where the user clicked the map interface

Sign In or Register to comment.