Getting country code with the help of device IP ad

2019-07-06 16:58发布

I am working on an app that have registration process and my requirements are:

Requirements:

  1. Automatically select country code with the help of device IP address tracing.
  2. Detect user location during registration and save it.

I searched a bit but did not find any useful information that would lead to an answer, there must be way but what is that? Please let me guide to the way

2条回答
混吃等死
2楼-- · 2019-07-06 17:20

If you address from user as an input during registration, you can find geo coordinates from address. Fore more information see https://developers.google.com/maps/documentation/geocoding/#Geocoding

Regarding country code from IP address, you can also utilize an online service like http://www.whois.net/ip-address-lookup/ and parse the response to retrieve the country code. Here is how you can parse it (the code is in PHP but you can easily modify it)

查看更多
等我变得足够好
3楼-- · 2019-07-06 17:33

Get user location:

String locationProvider = LocationManager.NETWORK_PROVIDER;
// Or use LocationManager.GPS_PROVIDER
Location lastKnownLocation = locationManager.getLastKnownLocation(locationProvider);

http://developer.android.com/guide/topics/location/strategies.html

Use GeoCoder to get the Address (with country)

GeoCoder.getFromLocation()

http://developer.android.com/reference/android/location/Geocoder.html

查看更多
登录 后发表回答