Comments (21)
非常好的建议!
from data-sync.
这个工具接口我来写吧,打算用百度的正逆地理编码来实现。
from data-sync.
https://restapi.amap.com/v3/geocode/geo
from data-sync.
建议高德也弄了
from data-sync.
from data-sync.
这本来就是高德的api
from data-sync.
嗯 好的
from data-sync.
这个有访问的上限次数吗?如果有上限,我们可否把这些数据存储到一个小数据库。
from data-sync.
from data-sync.
毕竟高德api应该也是商用的,我们目前是不是只对经纬度有需求?不用每次都去访问他的api。如果需要账号,我们可以搜集一些账号,分省市把数据弄下来。然后导入到我们可用的数据库。
from data-sync.
1000 个人开发者
from data-sync.
先走数据库 查询一下是否有值,没有走接口查询相关信息
from data-sync.
写错 6000次/日
from data-sync.
我们这里的地址信息不同于快递,目前精确到县就可以吧。全国县级行政区划单位有2845个,其中市辖区963个、县级市382个、县1329个。如果有缓存,应该没有问题的。不需要单独存储。
from data-sync.
我觉得可以使用高德的API。理论上位置精确到县,需要3个账号就能够了。大家觉得怎么样?如果可以,nwljy你去联系一下 这个项目的架构同学?
from data-sync.
配置保存在config目录的config.default.ts,然后调用 ctx.app.config.
var XMLHttpRequest=null
var request=null
/**
- Open the connection. Currently supports local server requests.
- @param string method Connection method (eg GET, POST)
- @param string url URL for the connection.
- @param boolean async Asynchronous connection. Default is true.
- @param string user Username for basic authentication (optional)
- @param string password Password for basic authentication (optional)
*/
var requestDatautils = {
getHttpReponseData:function(option,responseCallBack){
XMLHttpRequest= require("xmlhttprequest").XMLHttpRequest;
var xmlhttp = new XMLHttpRequest();
if(option.requestData!=null){
console.dir("send-----------"+option.requestData);
var url=option.url+"?"+encodeFormData(option.requestData);
console.log(url);
xmlhttp.open("GET",url, option.asynch,option.user, option.password);
}else{
xmlhttp.open("GET",option.url, option.asynch,option.user, option.password);
}
if(option.headers!=null) {
for(var key in option.headers) {
if(option.headers.hasOwnProperty(key)){
xmlhttp.setRequestHeader(key,option.headers[key]);
}
}
}
xmlhttp.onreadystatechange = function(){
//debugger;
//console.log(xmlhttp.readyState);
//console.log(xmlhttp.status);
if(xmlhttp.readyState == 4){
if(xmlhttp.status == 200){
return responseCallBack(xmlhttp.responseText);
}else if(xmlhttp.status == 404){
return responseCallBack(xmlhttp.responseText);
}else if(xmlhttp.status == 0){
return responseCallBack(xmlhttp.responseText);
}
}
};
xmlhttp.send(null);
},postHttpReponseData:function(option,responseCallBack){
XMLHttpRequest= require("xmlhttprequest").XMLHttpRequest;
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", option.url, asynch,option.user, option.password);
if(option.headers!=null) {
for(var key in option.headers) {
if(option.headers.hasOwnProperty(key)){
xmlhttp.setRequestHeader(key,option.headers[key]);
}
}
}
if(option.requestData!=null){
console.dir("send-----------"+option.requestData)
xmlhttp.send(option.requestData)
}else{
console.log("send-----------")
xmlhttp.send(null);
}
xmlhttp.onreadystatechange = function(){
//debugger;
console.log(xmlhttp.readyState);
console.log(xmlhttp.status);
if(xmlhttp.readyState == 4){
if(xmlhttp.status == 200){
return responseCallBack(xmlhttp.responseText)
}else if(xmlhttp.status == 404){
return responseCallBack(xmlhttp.responseText)
}else if(xmlhttp.status == 0){
return responseCallBack(xmlhttp.responseText)
}
}
};
},getHttpsReponseData:function(option,responseCallBack){
XMLHttpRequest = require("xmlhttprequest-ssl").XMLHttpRequest;
var xmlhttp = new XMLHttpRequest();
if(option.requestData!=null){
console.dir("send-----------"+option.requestData)
var url=option.url+"?"+encodeFormData(option.requestData);
xmlhttp.open("GET",url, option.asynch,option.user, option.password);
}else{
xmlhttp.open("GET",option.url, option.asynch,null,null);
}
if(option.headers!=null) {
for(var key in option.headers) {
if(option.headers.hasOwnProperty(key)){
xmlhttp.setRequestHeader(key,option.headers[key]);
}
}
}
xmlhttp.onreadystatechange = function(){
//debugger;
console.log(xmlhttp.readyState);
console.log(xmlhttp.status);
if(xmlhttp.readyState == 4){
if(xmlhttp.status == 200){
return responseCallBack(xmlhttp.responseText)
}else if(xmlhttp.status == 404){
return responseCallBack(xmlhttp.responseText)
}else if(xmlhttp.status == 0){
return responseCallBack(xmlhttp.responseText)
}
}
};
xmlhttp.send(null);
},postHttpsReponseData:function(option,responseCallBack){
XMLHttpRequest = require("xmlhttprequest-ssl").XMLHttpRequest;
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", option.url, option.asynch,option.user, option.password);
if(option.headers!=null) {
for(var key in option.headers) {
if(option.headers.hasOwnProperty(key)){
xmlhttp.setRequestHeader(key,option.headers[key]);
}
}
}
if(option.requestData!=null){
console.dir("send-----------"+option.requestData)
xmlhttp.send(option.requestData)
}else{
console.log("send-----------")
xmlhttp.send(null);
}
xmlhttp.onreadystatechange = function(){
//debugger;
console.log(xmlhttp.readyState);
console.log(xmlhttp.status);
if(xmlhttp.readyState == 4){
if(xmlhttp.status == 200){
return responseCallBack(xmlhttp.responseText)
}else if(xmlhttp.status == 404){
return responseCallBack(xmlhttp.responseText)
}else if(xmlhttp.status == 0){
return responseCallBack(xmlhttp.responseText)
}
}
};
}
};
//将对象{find:"pizza",zipcode:01234,radius:"1km"}变成表单编码的格式 find=pizza&zipcode=01234$radius=1km 的形式
function encodeFormData(data){
if(!data) return "";
var pairs=[];
for(var name in data){
if(!data.hasOwnProperty(name)) continue; //跳过继承方法
if(typeof data[name] == "function") continue;//跳过方法
var value=data[name].toString();
name=encodeURIComponent(name.replace("%20","+"));
value=encodeURIComponent(value.replace("%20","+"));
pairs.push(name+"="+value);
}
return pairs.join('&');
}
module.exports =requestDatautils;
用到的npm i xmlhttprequest和 npm i xmlhttprequest-ssl
from data-sync.
from data-sync.
先提交了高德的版本。百度的SN验证折腾了一下午没搞定,一直报错误代码211,SN校验错误。明天再找找解决方案。高德的版本比较简单,测试了一下坐标转换没什么问题。当然一个地址可能会对应多个坐标点,所以可以根据需要取所需要的坐标点,或者直接取第一个结果我觉得都OK。
from data-sync.
为何同时需要两个版本的库一起做?用一个 API 库是不是就可以了?以及精确到坐标存储应该支持一下,方便做 POI 查询,我会在数据存入时校验,如果原来获取过经纬度而地址没有发变化的字段,则不再获取,这样访问频次不会很高,只有新数据和地址变更数据才会请求。
from data-sync.
已经提交PR,新的代码里增加了本地缓存,可以按照地址,将数据进行缓存。使用getLocationFromCache函数可以直接获取缓存的数据,如果返回null,则未找到该数据。缓存中的地址可进行模糊匹配,目前的模糊匹配算法比较简单,就是字符串相似度。
代码里也删除了百度API相关配置。
from data-sync.
已经提交PR,新的代码里增加了本地缓存,可以按照地址,将数据进行缓存。使用getLocationFromCache函数可以直接获取缓存的数据,如果返回null,则未找到该数据。缓存中的地址可进行模糊匹配,目前的模糊匹配算法比较简单,就是字符串相似度。
代码里也删除了百度API相关配置。
PR 相关说明,直接在 PR 里评论哈
from data-sync.
Related Issues (20)
- [WeeklyReport] Weekly report for data-sync 2020-6-15 to 2020-6-22
- [WeeklyReport] Weekly report for data-sync 2020-6-22 to 2020-6-29
- [WeeklyReport] Weekly report for data-sync 2020-6-29 to 2020-7-6
- [WeeklyReport] Weekly report for data-sync 2020-7-6 to 2020-7-13
- [WeeklyReport] Weekly report for data-sync 2020-7-13 to 2020-7-20
- [WeeklyReport] Weekly report for data-sync 2020-7-20 to 2020-7-27
- [WeeklyReport] Weekly report for data-sync 2020-7-27 to 2020-8-3
- [WeeklyReport] Weekly report for data-sync 2020-8-3 to 2020-8-10
- [WeeklyReport] Weekly report for data-sync 2020-8-10 to 2020-8-17
- [WeeklyReport] Weekly report for data-sync 2020-8-17 to 2020-8-24
- [WeeklyReport] Weekly report for data-sync 2020-8-24 to 2020-8-31
- [WeeklyReport] Weekly report for data-sync 2020-8-31 to 2020-9-7
- [WeeklyReport] Weekly report for data-sync 2020-9-7 to 2020-9-14
- [WeeklyReport] Weekly report for data-sync 2020-9-14 to 2020-9-21
- [WeeklyReport] Weekly report for data-sync 2020-9-21 to 2020-9-28
- [WeeklyReport] Weekly report for data-sync 2020-9-28 to 2020-10-5
- [WeeklyReport] Weekly report for data-sync 2020-10-5 to 2020-10-12
- [WeeklyReport] Weekly report for data-sync 2020-10-12 to 2020-10-19
- [WeeklyReport] Weekly report for data-sync 2020-10-19 to 2020-10-26
- [WeeklyReport] Weekly report for data-sync 2020-10-26 to 2020-11-2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from data-sync.