GithubHelp home page GithubHelp logo

Comments (21)

frank-zsy avatar frank-zsy commented on September 28, 2024

非常好的建议!

from data-sync.

tyisme614 avatar tyisme614 commented on September 28, 2024

这个工具接口我来写吧,打算用百度的正逆地理编码来实现。

from data-sync.

nwljy avatar nwljy commented on September 28, 2024

https://restapi.amap.com/v3/geocode/geo

from data-sync.

nwljy avatar nwljy commented on September 28, 2024

建议高德也弄了

from data-sync.

wangzhen11aaa avatar wangzhen11aaa commented on September 28, 2024

https://restapi.amap.com/v3/geocode/geo
测试通过了吗?

from data-sync.

nwljy avatar nwljy commented on September 28, 2024

这本来就是高德的api

from data-sync.

tyisme614 avatar tyisme614 commented on September 28, 2024

嗯 好的

from data-sync.

wangzhen11aaa avatar wangzhen11aaa commented on September 28, 2024

这个有访问的上限次数吗?如果有上限,我们可否把这些数据存储到一个小数据库。

from data-sync.

nwljy avatar nwljy commented on September 28, 2024

from data-sync.

wangzhen11aaa avatar wangzhen11aaa commented on September 28, 2024

毕竟高德api应该也是商用的,我们目前是不是只对经纬度有需求?不用每次都去访问他的api。如果需要账号,我们可以搜集一些账号,分省市把数据弄下来。然后导入到我们可用的数据库。

from data-sync.

nwljy avatar nwljy commented on September 28, 2024

1000 个人开发者

from data-sync.

nwljy avatar nwljy commented on September 28, 2024

先走数据库 查询一下是否有值,没有走接口查询相关信息

from data-sync.

nwljy avatar nwljy commented on September 28, 2024

写错 6000次/日

from data-sync.

wangzhen11aaa avatar wangzhen11aaa commented on September 28, 2024

我们这里的地址信息不同于快递,目前精确到县就可以吧。全国县级行政区划单位有2845个,其中市辖区963个、县级市382个、县1329个。如果有缓存,应该没有问题的。不需要单独存储。

from data-sync.

wangzhen11aaa avatar wangzhen11aaa commented on September 28, 2024

我觉得可以使用高德的API。理论上位置精确到县,需要3个账号就能够了。大家觉得怎么样?如果可以,nwljy你去联系一下 这个项目的架构同学?

from data-sync.

nwljy avatar nwljy commented on September 28, 2024

配置保存在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.

nwljy avatar nwljy commented on September 28, 2024

@tyisme614

from data-sync.

tyisme614 avatar tyisme614 commented on September 28, 2024

先提交了高德的版本。百度的SN验证折腾了一下午没搞定,一直报错误代码211,SN校验错误。明天再找找解决方案。高德的版本比较简单,测试了一下坐标转换没什么问题。当然一个地址可能会对应多个坐标点,所以可以根据需要取所需要的坐标点,或者直接取第一个结果我觉得都OK。

from data-sync.

frank-zsy avatar frank-zsy commented on September 28, 2024

为何同时需要两个版本的库一起做?用一个 API 库是不是就可以了?以及精确到坐标存储应该支持一下,方便做 POI 查询,我会在数据存入时校验,如果原来获取过经纬度而地址没有发变化的字段,则不再获取,这样访问频次不会很高,只有新数据和地址变更数据才会请求。

from data-sync.

tyisme614 avatar tyisme614 commented on September 28, 2024

已经提交PR,新的代码里增加了本地缓存,可以按照地址,将数据进行缓存。使用getLocationFromCache函数可以直接获取缓存的数据,如果返回null,则未找到该数据。缓存中的地址可进行模糊匹配,目前的模糊匹配算法比较简单,就是字符串相似度。
代码里也删除了百度API相关配置。

from data-sync.

frank-zsy avatar frank-zsy commented on September 28, 2024

已经提交PR,新的代码里增加了本地缓存,可以按照地址,将数据进行缓存。使用getLocationFromCache函数可以直接获取缓存的数据,如果返回null,则未找到该数据。缓存中的地址可进行模糊匹配,目前的模糊匹配算法比较简单,就是字符串相似度。
代码里也删除了百度API相关配置。

PR 相关说明,直接在 PR 里评论哈

from data-sync.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.