如何通过IP地址获取设备国家地址? [英] How to get device country address through IP address?

查看:54
本文介绍了如何通过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" }

这篇关于如何通过IP地址获取设备国家地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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