如何在不使用核心位置服务的情况下获取用户的当前城市名称? [英] How to get the user's current city name without using the core location service?

查看:77
本文介绍了如何在不使用核心位置服务的情况下获取用户的当前城市名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,最初的要求是在启动应用程序时,移动应用程序将获得用户的当前位置(精确到城市).服务器/应用程序客户端将基于城市,提供与城市相关的内容.

So the original requirements was that on the launch of the app, the mobile app will get the current location of the user precise to City. Based on the city, the server/app client will give-city related content.

我知道,如果我可以使用核心位置服务,并不会太困难(因为您知道可疑(自我关注)的用户通常会为不太信任的应用程序禁用位置服务).

I know it would not be too difficult if I could use the core location service (since you know suspicious (self-concerned) users usually will disable the location service for a not-so-trusting app).

我已经在网上搜索了几个小时,并获得了以下解决方案的摘要,在这些解决方案中,需要您的帮助,以确定哪一种可能是我的最佳选择,或者您是否还有其他更好的选择.

I have searched the web for few hours and get an summary of following solutions where I need your help to decide which one could be my best option or if you have any other better ones.

使用[NSlocale autoupdatingCurrentLocale]

Using the [NSlocale autoupdatingCurrentLocale]

缺点:

  • a.苹果文档中调用返回值的解释:语言环境由当前用户选择的系统语言环境的设置组成,该设置覆盖了用户在系统偏好设置"中指定的任何自定义设置."从中我不明白什么是用户在系统偏好设置中指定的自定义设置" 参考链接

  • a.The explanation of the return value of the call from apple's document: "The locale is formed from the settings for the current user’s chosen system locale overlaid with any custom settings the user has specified in System Preferences." From which I don't understand what is "custom settings the user has specified in System Preferences" reference link

b.该值可能会产生误导,并且根本与用户的实际当前城市/国家无关.

b. This value could be misleading and not related with user's actual current city/country at all.

评论:如果有人可以向我解释语言环境如何根据用户设置进行更改,将不胜感激.

comments: I would be appreciated if anybody could explain me how the locale is changed according to user's setting.

获取当前的iPhone时区

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

缺点:

  • a.与上面的b相同,因为用户可以始终指定而不是让系统自动更新时区.
  • b.精度受到影响,只会列出首府城市.

评论:不太有前景,但易于实现

comments:Not very promising but easy to implement

使用基于IP的位置检测网络服务 根据我的阅读,该过程将涉及应用程序向服务器发送请求,服务器将在其中记录请求的IP(不要认为App本身可以正确获得自己的IP,因为它可能在内部本地网络)基于通过某些第三方服务记录的IP(具有IP db或其他一些可用的API),它将把城市信息返回给客户端.

Using IP based location detection webservice Based on my reading, the process will involve the app sending a request to a server where the server will record the IP of the request.(Don't think from App itself could get its own IP correctly since it may inside a local network) Based on the IP recorded through some third party service (with a IP db or some other available APIs), it will return the city information back to the client.

缺点:

  • a.我从来没有实现过这种东西,也不知道对于移动应用程序是否可行.
  • b.即使有可能,也不知道它是否比核心定位服务快.

评论:如果您知道iOS应用程序可以这样做,请告诉我.

comments: If you know it is possible for a iOS app to do so please let me know.

请给我您的任何想法,或者如果您知道的话,提出任何更好的解决方案.

Please kindly give me any thoughts you have or suggest any better solution if you know.

非常感谢您.

推荐答案

一种避免所有麻烦的预防措施是创建一个不会显得不太信任"的应用,并使用核心位置来获取地点.如果用户仍然不允许您的应用程序知道位置,并且必须知道他的城市,那么请让他从提供内容的城市列表中选择一个城市.当然,这开辟了一个巨大的漏洞,可用于获取任何城市的内容.只有您可以决定这是否是可以接受的折衷方案,以简化实施.

A preventive measure to avoid all your trouble would be to create an app that wouldn't appear 'not-so-trusting' and use core location to get the location. If a user still does not allow your app to know the location and knowing his city is a must, let him select a city from the list of cites for which content is available. Of course this opens up a huge hole allowing use to get the content for ANY city. Only you can decide if this is an acceptable tradeoff for simpler implementation.

如果您必须在没有核心位置的情况下自动了解CITY,则您提到的前两个选项区域设置"和时区"是无用的,因为它们每个都包含大量城市.另外,正如您提到的,它们取决于用户的设置.

If you must know the CITY automatically without core location, the first two options you mentioned, 'locale' and 'time zone' are useless as each of them encompasses large number of cities. Also, as you mentioned they're dependent on user's settings.

因此,最好使用GeoIP或某些此类服务对Web服务请求的IP地址进行反向地理编码.您可以在网上找到很多关于此的讨论和参考.

So reverse geocoding the IP address of a web service request using GeoIP or some such service is your best bet. You can find a lot of discussion and references for this on the web.

这篇关于如何在不使用核心位置服务的情况下获取用户的当前城市名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆