简体   繁体   English

用户当前国家/地区 - 基于用户的当前位置

[英]User current country - based on current location of the user

I would like to check in which country the user is - I have tried a few ways but none give the requested result. 我想检查用户所在的国家/地区-我尝试了几种方法,但是都没有给出要求的结果。 My main goal is when the app launches check in which country the user is and based on this by pressing a button call a different phone number, For instance user can be in Canada use the app and by pressing the button dial an XXX number and next week with same Iphone be in the US and by pressing the same button dial a YYY number. 我的主要目标是当应用程序启动检查用户所在的国家/地区时,通过按下按钮拨打不同的电话号码,例如用户可以在加拿大使用应用程序并按下按钮拨打XXX号码然后同一个Iphone的周在美国,按相同的按钮拨打YYY号码。

I have tried using CoreTelephony but this is good only for 4.0 and up i want my app to support earlier versions of iOS also tried Geocode but i do not want to display a map in my app. 我曾尝试使用CoreTelephony但这仅适用于4.0及更高版本,我希望我的应用程序支持iOS的早期版本,还尝试了Geocode,但我不想在我的应用程序中显示地图。

Any guidance will be appreciated. 任何指导将不胜感激。

Get your current location and reverse geocode it. 获取您的当前位置并对其进行反向地理编码。

Get your current location using CLLocationManager. 使用CLLocationManager获取您的当前位置。 Reverse geocoding is supported by iOS SDK 5, so if you need support versions below 5.0, you need to use external geocoding service. iOS SDK 5支持反向地理编码,因此如果您需要5.0以下的支持版本,则需要使用外部地理编码服务。 For example, Goolge Maps Reverse Geocoding, that is described in details here: http://code.google.com/apis/maps/documentation/geocoding/#ReverseGeocoding 例如,Goolge Maps反向地理编码,在此处详细介绍: http//code.google.com/apis/maps/documentation/geocoding/#ReverseGeocoding

What you need to do, just send a request like below: http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true and you'll get back a JSON with formatted address components. 您需要做什么,只需发送如下请求: http//maps.googleapis.com/maps/api/geocode/json ?latlng = 40.714224,-73.961452&_sensor = true ,您将获得格式化的JSON地址组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM