开启辅助访问      

站内搜索

搜索
热搜: 下载 1.19 1.20

Minecraft(我的世界)苦力怕论坛

[开发教程] 腾讯地图获取您的ip定位

发表于 2023-9-10 09:51:06 来自手机 | 显示全部楼层 |阅读模式 IP:广东省

kep请去相关网站申请
  1. <!DOCTYPE html>
  2. <html lang="en">

  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7.     <title>IP定位</title>
  8. </head>
  9. <script charset="utf-8" src="https://map.qq.com/api/gljs?v=1.exp&libraries=service&key=6F4BZ-6QXKL-473PF-EJUG7-6Y5MQ-6CBH7"></script>

  10. <body>
  11.     <div id="container"></div>
  12.     <div id="panel">
  13.         <p><input type='text' id='ipInput' placeholder="输入IP地址(默认为请求端的IP)" size='30'/><input type='button' id='locate' value='搜索所在位置' onclick='locate()' /></p>
  14.         <p id="ipLocationResult"></p>
  15.     </div>
  16. </body>


  17. <script type="text/javascript">
  18. var map = new TMap.Map('container', {
  19.   zoom: 14,
  20.   center: new TMap.LatLng(40.0402718, 116.2735831),
  21. });
  22. var ipLocation = new TMap.service.IPLocation(); // 新建一个IP定位类
  23. var markers = new TMap.MultiMarker({
  24.   map: map,
  25.   geometries: [],
  26. });
  27. function locate() {
  28.   var ipInput = document.getElementById('ipInput').value;
  29.   var params = ipInput ? { ip: ipInput } : {};
  30.   ipLocation
  31.     .locate(params)
  32.     .then((result2) => {
  33.       // 未给定ip地址则默认使用请求端的ip
  34.       var { result } = result2;
  35.       markers.updateGeometries([
  36.         {
  37.           id: 'main',
  38.           position: result.location, // 将所得位置绘制在地图上
  39.         },
  40.       ]);
  41.       map.setCenter(result.location);
  42.       document.getElementById(
  43.         'ipLocationResult'
  44.       ).innerText = `您的IP/您输入的IP所在位置:${result.ad_info.nation},${result.ad_info.province}`;
  45.     })
  46.     .catch((error) => {
  47.       document.getElementById(
  48.         'ipLocationResult'
  49.       ).innerText = `错误:${error.status},${error.message}`;
  50.     });
  51. }
  52. locate();
  53. </script>
  54. </html>
复制代码


这是例子

结果
Screenshot_2023-09-10-09-51-28-58_503f23bebdf1e187f8a3e223d715854e.jpg
苦力怕论坛,感谢有您~
回复

使用道具 举报

 楼主| 发表于 2023-9-10 09:52:33 来自手机 | 显示全部楼层 IP:广东省
本帖最后由 阿巴ing_ 于 2023-9-10 09:55 编辑

lbs.qq.com
相关网站

我也不知道怎么只显示位置文字别问我
来自 2# 2023-9-10 09:52:33 回复 收起回复
苦力怕论坛,感谢有您~
回复 支持

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

本站
关于我们
联系我们
坛史纲要
官方
哔哩哔哩
技术博客
下载
网易版
安卓版
JAVA
反馈
意见建议
教程中心
更多
捐助本站
QQ群
QQ群

QQ群

访问手机版

访问手机版

手机版|小黑屋|系统状态|klpbbs.com

粤公网安备 44200002445329号 | 由 木韩网络 提供云服务 | GMT+8, 2024-5-9 02:31

声明:本站与Mojang以及微软公司没有从属关系

Powered by Discuz! X3.4 粤ICP备2023071842号