如何通过IP地址获取设备国家地址?
我目前正在开展一个项目,该项目需要确定设备的国家/地区地址在哪里.我曾尝试使用 Montemagno 的 Geolocator,但问题是如果用户未在其设备上使用定位服务或 GPS.我认为使用 IP 地址可能是可能的,但我不知道如何或任何建议可能会有所帮助.谢谢.
I am currently working on a project requiring to identify where a device's country address is. I have tried using Montemagno's Geolocator but the problem is if the user does not use location services or gps on his device. I am thinking that it might be possible using IP address but I don't know how or any recommendation might help. Thanks.
您需要创建一个 http GET 请求以获取 JSON 格式的结果您可以使用 IP API 通过 IP 地址获取国家信息.示例获取请求:
You need to create a http GET request to get the results on JSON format you may use IP API to get country information by ip address. Example get request on :
返回一个包含国家信息的json数据.
return a json data which have country information.
{查询":24.48.0.1","状态": "成功","国家": "加拿大","countryCode": "CA","地区": "QC","regionName": "魁北克","city": "蒙特利尔","zip": "H1S",纬度":45.5808,lon":-73.5825,"timezone": "美国/多伦多","isp": "Le Groupe Videotron Ltee","org": "Videotron Ltee","as": "AS5769 Videotron Telecom Ltee"}
{ "query": "24.48.0.1", "status": "success", "country": "Canada", "countryCode": "CA", "region": "QC", "regionName": "Quebec", "city": "Montreal", "zip": "H1S", "lat": 45.5808, "lon": -73.5825, "timezone": "America/Toronto", "isp": "Le Groupe Videotron Ltee", "org": "Videotron Ltee", "as": "AS5769 Videotron Telecom Ltee" }