zoukankan      html  css  js  c++  java
  • js 定位当前城市(ip,省份,城市,邮编)接口定位(搜狐、新浪、百度、腾讯API)

    1.搜狐API

    <script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
    <script type="text/javascript">
    console.log(returnCitySN)
    //返回对象Object {cip: "122.70.200.146", cid: "110000", cname: "北京市"}
    </script>

    2.新浪API

    <script src="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js"></script>
    <script>
    var msg = remote_ip_info;
    console.log(msg)
    //返回对象Object {ret: 1, start: -1, end: -1, country: "中国", province: "北京",city: "北京"…}
    </script>

    3.新浪apijsonp

    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script type="text/javascript">
    $.getScript('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js', function(_result) {
    if (remote_ip_info.ret == '1') {
    console.log('国家:' + remote_ip_info.country +' 省:' + remote_ip_info.province + ' 市:' + remote_ip_info.city + ' 区:' + remote_ip_info.district + ' ISP:' + remote_ip_info.isp + ' 类型:' + remote_ip_info.type + ' 其他:' + remote_ip_info.desc);
    //返回结果 国家:中国 省:北京 市:北京 区: ISP: 类型: 其他:
    } else {
    alert('没有找到匹配的IP地址信息!');
    }
    });

    4.百度地图api

    function showLocation(data) {
    console.log(data.content.address_detail.city);
    }
    $.getScript("http://api.map.baidu.com/location/ip?ak=百度地图密匙&callback=showLocation");

    百度文档

    5.腾讯地图api

    $.getScript('https://apis.map.qq.com/ws/location/v1/ip?callback=showLocation&key=腾讯地图密匙&output=jsonp');
    function showLocation(data) {
    console.log(data.result.ad_info.city)
    }

  • 相关阅读:
    每日算法
    每日算法
    每日算法
    每日算法
    2020 蓝桥杯(省赛)校内模拟赛
    js 时间戳转特定格式的日期
    js正则表达式 replace替换url的参数
    7月/暑假集训总结1
    模板(ac):启发式合并
    [考试反思]0729NOIP模拟测试10
  • 原文地址:https://www.cnblogs.com/csj007523/p/12800628.html
Copyright © 2011-2022 走看看