Php 谷歌地图API v3代码不工作
下面的代码用于在PHP页面上显示地图。当单击侧栏上特定位置的链接时,将显示标记或图钉;当单击链接时,地图将缩放到所单击链接的位置。我最初是用V2编写代码的,现在正试图将其转换为V3。地图显示在页面上,但当我单击链接时,地图无法检索其位置。 单击链接时,它将调用下面代码中的showme函数 这是JavaScript代码Php 谷歌地图API v3代码不工作,php,javascript,google-maps,google-maps-api-3,Php,Javascript,Google Maps,Google Maps Api 3,下面的代码用于在PHP页面上显示地图。当单击侧栏上特定位置的链接时,将显示标记或图钉;当单击链接时,地图将缩放到所单击链接的位置。我最初是用V2编写代码的,现在正试图将其转换为V3。地图显示在页面上,但当我单击链接时,地图无法检索其位置。 单击链接时,它将调用下面代码中的showme函数 这是JavaScript代码 var geoCoder = null; var marker = null; var center = false; var show_info
var geoCoder = null;
var marker = null;
var center = false;
var show_info = false;
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(10.4032173, - 61.3719045),
zoom: 9,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"),
mapOptions);
}
function showAddress(address,description) {
var infowindow = new google.maps.InfoWindow({content:description});
geoCoder = new google.maps.Geocoder();
if (geoCoder) {
geoCoder.getPosition()(
address,
function(point) {
if (point){
if(center) map.setCenter(point, 13);
marker = new google.maps.Marker(point);
google.maps.event.addListener(marker, "click", function() {
infowindow.open(point, description);
});
marker.setMap(marker);
if(show_info) infowindow.open(point, description);
}
}
);
}
geoCoder = null;
}
function showLatLng(lat,lng,description) {
var point=new google.maps.LatLng(parseFloat(lat),parseFloat(lng));
if (point){
if(center) map.setCenter(point, 14);
marker = new google.maps.Marker({position:point,
map: map});
var infowindow = new google.maps.InfoWindow({content:description});
google.maps.event.addListener(marker, "click", function() {
infowindow.open(point, description);
});
marker.setMap(maker);
if(show_info) infowindow.open(point, description);
}
}
function showme(name, address, lat, lng, contact, Link) {
var description = desc(name, address, contact, Link);
center = true;
show_info = true;
if (lat || lng) showLatLng(lat, lng, description);
else showAddress(address, description);
return false;
}
function desc(name, address, contact, Link) {
//var address = "<div class='googleTip'><div><h1>"+name+"</h1></div><p class='address'>"+address+"<br />"+contact+"<br />"+delivery+"</p><span class='mapLink'></span></div>";
var Address = ["<div class='googleTip' style='color:#000000; padding:5px'><h3>",
name, "</h3>", "<div>",
address, "<br />",
webLink, "</div></div>", ].join('');
return Address;
}
我该如何解决这个问题。我对此感到失望。您的showMe函数仍在使用API v2语法。GMarker应该是google.maps.Marker,GEvent.addListener应该是google.maps.event.addListener,map.openInfowindow需要根据新语法进行调整,类似以下未测试的内容:
function showLatLng(lat,lng,description) {
var point=new google.maps.LatLng(parseFloat(lat),parseFloat(lng));
if (point){
if(center_point) map.setCenter(point, 14);
marker = new google.maps.Marker({position:point,
map: map});
var infowindow = new google.maps.InfoWindow({content:description});
google.maps.event.addListener(marker, "click", function() {
infowindow.open(point, marker);
});
marker.setMap(map);
if(show_info) infowindow.open(point, marker);
}
}
geocoder的回调函数也有同样的问题。在showAddress函数中,使用geo.getPosition而不是geocoder.getPosition。这就是问题所在吗?没有地图;在V3中。检查文档。您还可以删除.joint之前的最后一个。它应该是google.maps.event.addListener。。。在版本3中,我编辑了原始代码以显示所做的更改。但它仍然不起作用。当我点击页面上的链接时,地图上没有显示位置。我知道showme函数有问题,但我看不出来。请帮忙。你修好语法了吗?我认为没有getPosition方法?控制台会报告哪些javascript错误?我的google api控制台不会报告任何错误。我认为这只是一个逻辑错误。请查看文档以了解更多信息。一个包含完整代码和html的JSFIDLE可能也会有帮助。我需要在geocoder中加入请求和回调函数吗?我试过了,但没用。showme函数现在也是V3格式吗?