dictionaryfirebaselocationmapkitclplacemark

Get annotations for a specified area/country (from database)


I'm developing an iOS app that works with locations (placemarks) added by the users. The locations added by the users contain data (like title and description). I want to give users (admins) access to change data for the locations sent in, but ONLY for a restricted area like a city or country.

I am using Firebase to store the locations (so I can reach them for both iOS and Android), but I don't know in which structure I must store them. I thought first that I could store the locations based on the CLPlacemark country attribute sent in by users (like if I'd sent a location to Firebase with a placemark.country equals to "Norway", the location would be added to the array "norway" inside a main array named "locations").

But the MapKit response language is based on the device language, so if the device language was Norwegian the placemark's country would be "Norge" instead of "Norway" and will then not be saved to the "norway"-array. Because of this I can't verify if the admin has access to a specific country, because the locations can be saved in "norway" or "norge" or the country name in other languages.

How can I make the admins have access to change data for certain countries/cities if I can't sort the locations in Firebase?

Is there a way to check the country name and city name in english and then add them to Firebase based on the English name or do I have to store all the locations in one big array and validate them when I load them from Firebase?


Solution

  • You need to disassociate your data from how it's stored in Firebase. There's 100 ways to do this but here's one.

    Each country_id_0 is created with childByAutoId.

    countries
       country_id_0
         USA: "Norway"
         Norwegian: "Norge"
       country_id_1
         USA: "France"
         Norwegian: "Frankrike"
    

    And a structure to store your admins.

    admins
       user_id_0
          country_id_0: true
       user_id_1
          country_id_1: true
    

    With this structure, user_id_0 has admin privileges over country_id_0 (Norway) and user_id_1 can admin country_id_1 (France). The user_id_x is the uid found from authData.uid.

    The code in your app will only reference country_id_0 - so the actual country name is disassociated from your code. Another benefit if the country name changes, it won't impact your code; just update the child nodes that contain the name string.

    If you need the actual name in some language you can simply reference

    countries/country_id_1/Norwegian

    which will return 'Frankrike'

    Also, if you are considering storing array's Firebase, there may be better options.