前端构建-根据ip得到地图

https://lbs.amap.com/api/javascript-api/example/location/get-city-name-by-ip-location
https://lbs.amap.com/api/webservice/guide/api/ipconfig
http://lbsyun.baidu.com/index.php?title=webapi/ip-api
https://blog.csdn.net/tel13259437538/article/details/79874874
http://lbsyun.baidu.com/cms/jsapi/reference/jsapi_reference.html#a7b28
http://lbsyun.baidu.com/jsdemo.htm#i8_2
http://chaipip.com/ip.php
data:{"ip":"182.149.105.21","ak":"toGFnmI4HUgy2EpwyCpMGZvS7GqePNnA","coor":"bd09ll"},
http://ip.taobao.com/service/getIpInfo.php?ip=182.149.105.21
https://www.feiniaomy.com/post/205.html
js get post:
https://www.cnblogs.com/xwgli/p/4457971.html
https://www.cnblogs.com/pauline/p/6696704.html
https://blog.csdn.net/educast/article/details/72724368

key 用的钟馗之眼平台的

打算是先请求api得到地名,再用地名请求得到地图(直接用ip得到地图的硬是没有找到)

1.先打算用js直接请求接口,同源策略。。。(js页面操作是会出现这个问题的,所以看都是请求本机页面)

先请求

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=toGFnmI4HUgy2EpwyCpMGZvS7GqePNnA"></script>
<title>IP定位获取当前城市</title>
</head>
<body>
<button type="button" id="pang" class="btn btn-info btn-lg " aria-haspopup="true" aria-expanded="false"><b>旁站</b></button>
<div id="allmap"></div>

</body>
</html>
<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">

$(function() {
$("#pang").click(function() {
$.ajax({
url:"http://api.map.baidu.com/location/ip",
type:"GET",
data:{"ip":"182.149.105.21","ak":"toGFnmI4HUgy2EpwyCpMGZvS7GqePNnA","coor":"bd09ll"},
dataType:'json',//服务器返回json格式数据
type:'get',//HTTP请求类型
timeout:10000,//超时时间设置为10秒;
headers:{"referer":"https://www.zoomeye.org/searchDetail"},
success:function(data){
return_data(data);
}
});
});
});
function return_data(data){
return data;
//处理得到城市
}
var city=return_data()
// 百度地图API功能
var map = new BMap.Map("allmap");
var point = new BMap.Point(116.331398,39.897445);
map.centerAndZoom(point,12);

function myFun(result){
map.setCenter(result);
alert("当前定位城市:"+cityName);
}
myFun(city)




</script>

还可以参考:https://www.feiniaomy.com/post/205.html 得到地名

但是估计还是有同源策略

2.

写个py的api发送得到地址吧

import requests
import json
headers={"referer":"https://www.zoomeye.org/"}
data={"ip":"182.149.105.21","ak":"toGFnmI4HUgy2EpwyCpMGZvS7GqePNnA","coor":"bd09ll"}
url="http://api.map.baidu.com/location/ip"
s=requests.get(url=url,params=data,headers=headers)
s=unicode(s.text)
print(json.loads(s)["address"].split("|")[2])

对应的js 接口:

。。。。

再用:得到地图

// 百度地图API功能
var map = new BMap.Map("allmap");
var point = new BMap.Point(116.331398,39.897445);
map.centerAndZoom(point,12);

function myFun(result){
map.setCenter(result);
alert("当前定位城市:"+cityName);
}
myFun(city)

2019.4.13

标签:

发表评论

电子邮件地址不会被公开。 必填项已用*标注