Best way to implement the user's location definition with Xamarin.Forms

Pierre-ChristopheDusPierre-ChristopheDus FRUniversity ✭✭✭
edited July 2016 in Xamarin.Forms

Hello,
I develop an app with Xamarin.Forms, that returns a list of items (stores, offers, ...à based on an address.
By default this adress takes in account the user's location, but he must be able to define a custom address.

I first wanted to use a searchbar to do this, but in all samples that I found, the searchbar is use to filter items, which is not my case...

So my second idea is to add a "subtitle" in the NavigationPage to display the current location, and to add a button to redefine it through a Toolbar icon.

=> What do you think about it?
Is it easily feasible?!

Answers

  • AdamPAdamP AUUniversity ✭✭✭✭✭

    @Pierre-ChristopheDus - the subtitle might require a custom renderer but other than that a toolbar item to open a new page to redefine the address seems like a reasonable approach.

  • Pierre-ChristopheDusPierre-ChristopheDus FRUniversity ✭✭✭

    @AdamP Thanks for your return.
    For the subtitle, I have added a row under the NavigationBar, by separating the ContentPage.Content in 2 parts: the subtitle, and the "main area". I don't know if this is the best approach or if something is feasable through a renderer on the navigation bar.

    But I also wonder where I need to set the geolocation process? (I search the coordinates through the Geolocator plugin, and then I do a reverse geocode to obtain the address). As I need to use it on several pages, I don't see which is the better way to use it:

    • at the arrival on the page?
    • before leaving the previous page?
    • at the start of the app (in the App.xaml.cs)?
  • AdamPAdamP AUUniversity ✭✭✭✭✭

    @Pierre-ChristopheDus - this depends on when you need the updated location.

    If you need it across you entire app when they open it, then I would use the OnStart method in your App.cs

    If you only need it only on the page and it needs to refresh every time you load that specific page, then I would do it on the OnAppearing of the page.

  • Pierre-ChristopheDusPierre-ChristopheDus FRUniversity ✭✭✭

    @AdamP I need to use this on 3 pages of my app. So I can to do it in the OnAppearing of each page, but doesn't it impact the performances?
    Isn't it possible to mix the 2 approaches by limiting the number of geolocating in the time (one time per hour for example)?

  • AdamPAdamP AUUniversity ✭✭✭✭✭

    @Pierre-ChristopheDus - you can cache the result if you need to keep referencing it, however if its every hour you may just want to do it once on OnStart in your App.cs.

    If you want to cache just create a wrapper function to store the value with a DateTime and return that unless the datetime expires. There is no proper caching solution in a PCL or Xamarin, however you can google a cache store and people have developed a few implementations.

  • Pierre-ChristopheDusPierre-ChristopheDus FRUniversity ✭✭✭
    edited July 2016

    @AdamP do you think that I can use the Plugin.Settings plugin as caching solution?
    Also, I always ask me about the most intuitive way to implement geolocation on my pages.
    I studied 2 existing applications:

    • The first is closer to my case, as the main page is a list of results based on geolocation:

      on iOS

      on Android

    • The second seems easier to implement, but the render is less "native":

      on iOS

      on Android

    What do you think about this?

  • AdamPAdamP AUUniversity ✭✭✭✭✭

    @Pierre-ChristopheDus - with your caching you can just store it in a static variable in memory if you want. I imagine each time they start the application you would want to get the location again. If they enter in a custom address, I suppose you might want to cache that across application restarts. For that scenario, yes the Settings Plugin is a good option.

    As for your UI Design, both are a good solutions, this is really going to come down to user acceptance testing. However you are right in that the second one with the tabs isn't really iOS friendly. I always highly recommend going with the native approach for each platform and not making one UI that is the same across all platforms.

  • ZamanKhanZamanKhan USMember ✭✭

    @Pierre-ChristopheDus said:
    @AdamP do you think that I can use the Plugin.Settings plugin as caching solution?
    Also, I always ask me about the most intuitive way to implement geolocation on my pages.
    I studied 2 existing applications:

    • The first is closer to my case, as the main page is a list of results based on geolocation:

      on iOS

      on Android

    • The second seems easier to implement, but the render is less "native":

      on iOS

      on Android

    What do you think about this?

    can you share me XML of this design on my id [email protected]

  • acliceaclice VNMember ✭✭

    @Pierre-ChristopheDus said:
    @AdamP do you think that I can use the Plugin.Settings plugin as caching solution?
    Also, I always ask me about the most intuitive way to implement geolocation on my pages.
    I studied 2 existing applications:

    • The first is closer to my case, as the main page is a list of results based on geolocation:

      on iOS

      on Android

    • The second seems easier to implement, but the render is less "native":

      on iOS

      on Android

    What do you think about this?

    Can you share me this layout ? [email protected]

Sign In or Register to comment.