Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.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
Javascript 从地址将谷歌地图居中_Javascript_Maps - Fatal编程技术网

Javascript 从地址将谷歌地图居中

Javascript 从地址将谷歌地图居中,javascript,maps,Javascript,Maps,我想把谷歌地图放在我从laravel数据库得到的地址的中心。然而,地图没有显示。问题在哪里 函数initMap(){ getLocations(); } 函数getLocations(){ var http=new XMLHttpRequest(); http.open('GET','https://maps.googleapis.com/maps/api/geocode/json?address=“+{{$address}+'&key=AIzaSyCkCcwU02g9AlDkBzL6S6M

我想把谷歌地图放在我从laravel数据库得到的地址的中心。然而,地图没有显示。问题在哪里


函数initMap(){
getLocations();
}
函数getLocations(){
var http=new XMLHttpRequest();
http.open('GET','https://maps.googleapis.com/maps/api/geocode/json?address=“+{{$address}+'&key=AIzaSyCkCcwU02g9AlDkBzL6S6MbRBUNi8Z7atI”,真);
http.onload=function(){
var坐标=JSON.parse(http.responseText);
坐标=坐标['results'][0]['geometry']['location'];
var事件={lat:coordinates['lat'],lng:coordinates['lng']};
var map=new google.maps.map(document.getElementById('map'){
缩放:12,
中心:活动
});
var marker=new google.maps.marker({
位置:事件,
地图:地图
});
};
http.send();
}

您应该显示更多的代码,并给出返回的错误代码。 无论如何,我认为要么是你传递地址的方式,要么是你html设置的方式。一种快速检查地址是否正确的方法是发出警报。或者您可以测试服务器的200响应

请看下面的代码 下面是片段


#地图{
高度:400px;
宽度:100%;
}
我的谷歌地图演示
函数initMap(){
var uluru={lat:-25.363,液化天然气:131.044};
var map=new google.maps.map(document.getElementById('map'){
缩放:4,
中心:乌卢鲁
});
var marker=new google.maps.marker({
职位:乌卢鲁,
地图:地图
});
getLocations();
}
函数getLocations(){
var http=new XMLHttpRequest();
http.open('GET','https://maps.googleapis.com/maps/api/geocode/json?address=1600+圆形剧场+公园道,+山景,+CA&key=Aizasyckcwu02g9aldkbzl6s6mbrbuni8z7ati',正确);
http.onload=function(){
var坐标=JSON.parse(http.responseText);
坐标=坐标['results'][0]['geometry']['location'];
var事件={lat:coordinates['lat'],lng:coordinates['lng']};
var map=new google.maps.map(document.getElementById('map'){
缩放:12,
中心:活动
});
var marker=new google.maps.marker({
位置:事件,
地图:地图
});
};
http.send();
}

在公开帖子中包含私钥也不是一个好主意。;-)