Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在谷歌地图上搜索地址的脚本_Java_Regex_R_Google Maps_Web Scraping - Fatal编程技术网

Java 在谷歌地图上搜索地址的脚本

Java 在谷歌地图上搜索地址的脚本,java,regex,r,google-maps,web-scraping,Java,Regex,R,Google Maps,Web Scraping,我有纽约地区1100家医院的名字。我需要从谷歌上找到这些医院的地址。我正在寻找一些脚本,我可以用来提供所有这些医院的名称,它可以返回一个地址我。该脚本可以返回一个简单的谷歌搜索结果。 输入格式: Hospital Name Center for Ambulatory Surgery Genetic Diagnostic Labs Inc Hospital Name Hospital Address Center for Ambulatory Surgery 3112 Sheridan

我有纽约地区1100家医院的名字。我需要从谷歌上找到这些医院的地址。我正在寻找一些脚本,我可以用来提供所有这些医院的名称,它可以返回一个地址我。该脚本可以返回一个简单的谷歌搜索结果。 输入格式:

Hospital Name
Center for Ambulatory Surgery
Genetic Diagnostic Labs Inc
Hospital Name   Hospital Address
Center for Ambulatory Surgery   3112 Sheridan Dr, Amherst, NY 14226
Genetic Diagnostic Labs Inc 490 Delaware Ave, Buffalo, NY 14202
所需的输出格式:

Hospital Name
Center for Ambulatory Surgery
Genetic Diagnostic Labs Inc
Hospital Name   Hospital Address
Center for Ambulatory Surgery   3112 Sheridan Dr, Amherst, NY 14226
Genetic Diagnostic Labs Inc 490 Delaware Ave, Buffalo, NY 14202
解决方案具有,但结果可能不太准确:

var NY_latlng=new google.maps.latlng(40.828624,-73.898605);
map=new google.maps.map(document.getElementById('map-canvas'){
中心:纽约拉廷,
缩放:15
});
var医院=[];
var hospitals_names=[“门诊手术中心”、“基因诊断实验室公司”]//在此处插入您的完整列表
var service=newgoogle.maps.places.PlacesService(地图);
医院名称。forEach(功能(名称){
service.textSearch(
{
查询:姓名,
地点:纽约,
半径:50000,//以米为单位
},功能(结果、状态){
if(status==google.maps.places.PlacesServiceStatus.OK){
var医院={name:name,地址:[]};
$(“#地址列表”)。追加(“+name+”
    ”); 对于(var i=0;iul”).append(“
  • ”+结果[i]。格式化的#u地址); } 医院.推送(医院); } });
  • 您可以使用
    ggmap
    包在R中执行此操作,但可能不足以可靠地生成所需的结果。例如,此地理编码尝试失败:

    geocode("Genetic Diagnostic Labs Inc")
    
    Warning message:
    geocode failed with status ZERO_RESULTS, location = "Genetic Diagnostic Labs Inc" 
    
    为了说明解决方案,我在谷歌搜索中添加了“NY”:

    library(ggmap)
    hospital_names <- c("Center for Ambulatory Surgery", "Genetic Diagnostic Labs Inc")
    address_vec <- lapply(hospital_names, function(x) revgeocode(as.numeric(geocode(paste(x,", NY")))))
    result <- data.frame(name = hospital_names, address = unlist(address_vec))
    

    但是这些不是您指定的地址-您可能需要改进您的输入。

    您是否尝试过编写代码或研究合适的API?Google的API有一个新的解决方案。另请参见
    dismo::geocode
    ,它采用地名向量。