Php 谷歌地图地理编码在TSO主机上不起作用
我使用以下代码将地址转换为经度和纬度。代码取自Php 谷歌地图地理编码在TSO主机上不起作用,php,google-maps,google-maps-api-3,Php,Google Maps,Google Maps Api 3,我使用以下代码将地址转换为经度和纬度。代码取自 欢迎任何帮助。TSO主机支持似乎无法解决这个问题。为了确保它与服务器相关,我建议您尝试在页面中使用JS。请尝试通过更改您的div ID和密钥来实现以下代码。还要将地址变量传递到相关位置 <script> function initialize() { var center; var geocoder = new google.maps.Geocoder(); geocod
欢迎任何帮助。TSO主机支持似乎无法解决这个问题。为了确保它与服务器相关,我建议您尝试在页面中使用JS。请尝试通过更改您的div ID和密钥来实现以下代码。还要将地址变量传递到相关位置
<script>
function initialize() {
var center;
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': $AdressYouGotFromThePost}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var mycenter = new google.maps.LatLng(results[0].geometry.location.lat(),results[0].geometry.location.lng());//
var mapProp = {
center:mycenter,
zoom:11
};
var map=new google.maps.Map(document.getElementById("YOURDIVID"),mapProp);
var request = {
location: mycenter,
radius: '20000',
types: ['bar,night_club,cafe,museum,movie_theater,zoo,aquapark']
};
service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
}
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
var place = results[i];
createPhotoMarker(results[i]);
}
}
}
function createPhotoMarker(place) {
var photos = place.photos;
if (!photos) {
return;
}
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location,
title: place.name
//icon: photos[0].getUrl({'maxWidth': 55, 'maxHeight': 55})
});
//console.log(photos[0].getUrl({'maxWidth': 105, 'maxHeight': 105}));
var contenthtml = "<p>"+place.name+"</p><img src="+photos[0].getUrl({'maxWidth': 105, 'maxHeight': 105})+" width='105px'/>";
var infowindow = new google.maps.InfoWindow({
content:contenthtml
});
google.maps.event.addListener(marker,'click',function() {
map.setZoom(17);
map.setCenter(marker.getPosition());
infowindow.open(map,marker);
});
}
});
}
</script>
<script async="" defer="" src="https://maps.googleapis.com/maps/api/js?key=YOURACCESSKEYHERE&callback=initialize&libraries=places">
函数初始化(){
var中心;
var geocoder=new google.maps.geocoder();
geocoder.geocode({'address':$addressyougotfromthepost},函数(结果,状态){
if(status==google.maps.GeocoderStatus.OK){
var mycenter=new google.maps.LatLng(结果[0].geometry.location.lat(),结果[0].geometry.location.lng())//
var mapProp={
中心:迈森特,
缩放:11
};
var map=new google.maps.map(document.getElementById(“YOURDIVID”),mapProp);
var请求={
地点:迈森特,
半径:“20000”,
类型:[“酒吧、夜总会、咖啡馆、博物馆、电影院、动物园、水上公园”]
};
服务=新的google.maps.places.PlacesService(地图);
服务.nearbySearch(请求、回调);
}
函数回调(结果、状态){
if(status==google.maps.places.PlacesServiceStatus.OK){
对于(var i=0;i”;
var infowindow=new google.maps.infowindow({
内容:contenthtml
});
google.maps.event.addListener(标记,'click',函数(){
map.setZoom(17);
map.setCenter(marker.getPosition());
信息窗口。打开(地图、标记);
});
}
});
}
为了确保它与服务器相关,我建议您尝试在页面中使用JS。请尝试通过更改您的div ID和密钥来实现以下代码。还要将地址变量传递到相关位置
<script>
function initialize() {
var center;
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': $AdressYouGotFromThePost}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var mycenter = new google.maps.LatLng(results[0].geometry.location.lat(),results[0].geometry.location.lng());//
var mapProp = {
center:mycenter,
zoom:11
};
var map=new google.maps.Map(document.getElementById("YOURDIVID"),mapProp);
var request = {
location: mycenter,
radius: '20000',
types: ['bar,night_club,cafe,museum,movie_theater,zoo,aquapark']
};
service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
}
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
var place = results[i];
createPhotoMarker(results[i]);
}
}
}
function createPhotoMarker(place) {
var photos = place.photos;
if (!photos) {
return;
}
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location,
title: place.name
//icon: photos[0].getUrl({'maxWidth': 55, 'maxHeight': 55})
});
//console.log(photos[0].getUrl({'maxWidth': 105, 'maxHeight': 105}));
var contenthtml = "<p>"+place.name+"</p><img src="+photos[0].getUrl({'maxWidth': 105, 'maxHeight': 105})+" width='105px'/>";
var infowindow = new google.maps.InfoWindow({
content:contenthtml
});
google.maps.event.addListener(marker,'click',function() {
map.setZoom(17);
map.setCenter(marker.getPosition());
infowindow.open(map,marker);
});
}
});
}
</script>
<script async="" defer="" src="https://maps.googleapis.com/maps/api/js?key=YOURACCESSKEYHERE&callback=initialize&libraries=places">
函数初始化(){
var中心;
var geocoder=new google.maps.geocoder();
geocoder.geocode({'address':$addressyougotfromthepost},函数(结果,状态){
if(status==google.maps.GeocoderStatus.OK){
var mycenter=new google.maps.LatLng(结果[0].geometry.location.lat(),结果[0].geometry.location.lng())//
var mapProp={
中心:迈森特,
缩放:11
};
var map=new google.maps.map(document.getElementById(“YOURDIVID”),mapProp);
var请求={
地点:迈森特,
半径:“20000”,
类型:[“酒吧、夜总会、咖啡馆、博物馆、电影院、动物园、水上公园”]
};
服务=新的google.maps.places.PlacesService(地图);
服务.nearbySearch(请求、回调);
}
函数回调(结果、状态){
if(status==google.maps.places.PlacesServiceStatus.OK){
对于(var i=0;i”;
var infowindow=new google.maps.infowindow({
内容:contenthtml
});
google.maps.event.addListener(标记,'click',函数(){
map.setZoom(17);
map.setCenter(marker.getPosition());
信息窗口。打开(地图、标记);
});
}
});
}
使用php方法将地址转换为经度和纬度,如本例所示
导致TSO主机共享云服务器上达到api限制。使用API密钥似乎没有任何区别。解决方案是不使用php方法,而是使用Javascript方法,如Google示例-使用php方法将地址转换为经度和纬度,如本例所示
导致TSO主机共享云服务器上达到api限制。使用API密钥似乎没有任何区别。解决方案是不使用php方法,而是使用Javascript方法,如谷歌示例所示-你能检查控制台日志中googleapis上的Javascript错误吗,如果你在这里看到任何帖子吗?控制台中没有错误这是一个共享主机,而前一个主机没有?两者都是共享主机如果它是公共的?你能在googleapis上检查控制台日志中的Javascript错误吗?如果你在这里看到任何帖子吗?控制台中没有错误这是一个共享主机,而前一个主机没有。两者都是共享主机。如果是公共的,你能发布页面地址吗?不确定我做错了什么,但代码只是给了我一个白色屏幕。它应该是什么样子的?我正在检查你之前发送的同一页,但我没有看到我发布的脚本和你需要创建的div。它应该看起来有点像
<script>
function initialize() {
var center;
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': $AdressYouGotFromThePost}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var mycenter = new google.maps.LatLng(results[0].geometry.location.lat(),results[0].geometry.location.lng());//
var mapProp = {
center:mycenter,
zoom:11
};
var map=new google.maps.Map(document.getElementById("YOURDIVID"),mapProp);
var request = {
location: mycenter,
radius: '20000',
types: ['bar,night_club,cafe,museum,movie_theater,zoo,aquapark']
};
service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
}
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
var place = results[i];
createPhotoMarker(results[i]);
}
}
}
function createPhotoMarker(place) {
var photos = place.photos;
if (!photos) {
return;
}
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location,
title: place.name
//icon: photos[0].getUrl({'maxWidth': 55, 'maxHeight': 55})
});
//console.log(photos[0].getUrl({'maxWidth': 105, 'maxHeight': 105}));
var contenthtml = "<p>"+place.name+"</p><img src="+photos[0].getUrl({'maxWidth': 105, 'maxHeight': 105})+" width='105px'/>";
var infowindow = new google.maps.InfoWindow({
content:contenthtml
});
google.maps.event.addListener(marker,'click',function() {
map.setZoom(17);
map.setCenter(marker.getPosition());
infowindow.open(map,marker);
});
}
});
}
</script>
<script async="" defer="" src="https://maps.googleapis.com/maps/api/js?key=YOURACCESSKEYHERE&callback=initialize&libraries=places">