How to get the name of the current city without using the location service?

Thus, the initial requirements were that when you start the application, the mobile application will receive the exact location of the user, accurate in City. Based on the city, the server / application client will provide content related to the city.

I know that it would not be too difficult if I could use the location service (since you know that suspicious (self-observing) users usually turn off the location service for a not-so-trusted application).

I searched the Internet for several hours and get a summary of the following solutions in which I need your help to decide which one might be my best option, or if you have other best ones.

Using [NSlocale autoupdatingCurrentLocale]

minuses:

  • a. Explanation of the return value of the call from the Apple document: "The locale is formed from the settings for the user's system locales superimposed on any user settings that the user specified in System Preferences." What I don’t understand what is "user settings that the user specified in" System Preferences ", link link

  • b

    . This value can be misleading and generally not related to the actual current city / country of the user.

comments: I would appreciate it if someone could explain to me how the locale changes according to user settings.

Getting Current iPhone TimeZone

 NSTimeZone *localTime = [NSTimeZone systemTimeZone]; NSLog(@"Current local timezone is %@",[localTime name]); 

minuses:

  • a. the same as in paragraph b above, since the user can always specify, and not allow the system to automatically update the time zone.
  • b. accuracy will be indicated only in the capital.

Comments: Not very promising, but easy to implement

Using an IP- based location-based web service Based on my reading, the process will include an application sending a request to the server on which the server will record the request's IP . (Do not think that from the application itself it can get its own IP correctly, since it can be inside the local network). Based on the IP recorded through some third-party service (with IP db or some other available APIs), it will return the city information back to the client.

minuses:

  • a. I have never implemented such a thing, I do not know if this is possible for a mobile application.
  • b. Even if it’s possible, you don’t know if it’s faster than the location service.

comments: If you know that this is possible for an iOS application, please let me know.

Please kindly let me know any thoughts or suggest a better solution if you know.

Thank you very much.

+4
source share
2 answers

A preventative measure to avoid all your problems is to create an application that will not appear as “non-trusting” and use the location of the kernel to get the location. If the user still doesn’t let your application know the location and know that his city is required, let him choose a city from the list of citations for which content is available. Of course, this opens a huge hole that allows you to use content for ANY city. Only you can decide if this is an acceptable compromise for a simpler implementation.

If you need to know CITY automatically without a primary location, the first two options you specify: "locale" and "time zone" are useless, since each of them covers a large number of cities. In addition, as you mentioned, they depend on user preferences.

So, reverse geocoding the IP address of a web service request using GeoIP or any such service is your best bet. You can find many discussions and links for this on the Internet.

+1
source

NSlocale can be very inaccurate. My colleague bought an iPhone from New Zealand (he studied there). When I test my phone to get the locale, it still displays as New Zealand English.

Using IP is possible. I did a quick search and I found: -

You might want to take advantage of a good reading on top of the links.

I still think using Core Location is the best way to get the user's location.

0
source

All Articles